From 3b264988449806b8acf36d84fc7ed20e922d2768 Mon Sep 17 00:00:00 2001 From: robiso Date: Sat, 18 Mar 2017 19:30:37 +0100 Subject: [PATCH] Delete upload.php --- plugins/upload/upload.php | 100 -------------------------------------- 1 file changed, 100 deletions(-) delete mode 100644 plugins/upload/upload.php diff --git a/plugins/upload/upload.php b/plugins/upload/upload.php deleted file mode 100644 index d3f6479..0000000 --- a/plugins/upload/upload.php +++ /dev/null @@ -1,100 +0,0 @@ - - * @version 1.0.0 - */ - -defined('INC_ROOT') || die('Direct access is not allowed.'); - -wCMS::addListener('settings', 'addHtmlUploadForm'); -wCMS::addListener('before', 'uploadFile'); - -function addHtmlUploadForm ($args) { - $output = $args[0]; - $remove = '
Close settings
'; - $output = substr($output, 0, -(strlen($remove))); - $output .= '
' . $remove; - $args[0] = $output; - return $args; -} - -function uploadFile ($args) { - if ( ! isset($_FILES['upfile'])) return; - - $allowed = [ - 'jpg' => 'image/jpeg', - 'png' => 'image/png', - 'gif' => 'image/gif', - ]; - - try { - if ( - ! isset($_FILES['upfile']['error']) || - is_array($_FILES['upfile']['error']) - ) { - wCMS::alert('danger', 'Upload: invalid parameters.'); - wCMS::redirect(wCMS::$currentPage); - } - - switch ($_FILES['upfile']['error']) { - case UPLOAD_ERR_OK: - break; - case UPLOAD_ERR_NO_FILE: - wCMS::alert('danger', 'Upload: no file sent.'); - wCMS::redirect(wCMS::$currentPage); - case UPLOAD_ERR_INI_SIZE: - case UPLOAD_ERR_FORM_SIZE: - wCMS::alert('danger', 'Upload: exceeded filesize limit.'); - wCMS::redirect(wCMS::$currentPage); - default: - wCMS::alert('danger', 'Upload: unknown error.'); - wCMS::redirect(wCMS::$currentPage); - } - - $mimeType = ''; - if (class_exists('finfo')) { - $finfo = new finfo(FILEINFO_MIME_TYPE); - $mimeType = $finfo->file($_FILES['upfile']['tmp_name']); - } else if (function_exists('mime_content_type')) { - $mimeType = mime_content_type($_FILES['upfile']['tmp_name']); - } else { - $ext = strtolower(array_pop(explode('.', $_FILES['upfile']['name']))); - if (array_key_exists($ext, $allowed)) { - $mimeType = $allowed[$ext]; - } - } - - if (false === $ext = array_search( - $mimeType, - $allowed, - true - )) { - wCMS::alert('danger', 'Upload: invalid file format.'); - wCMS::redirect(wCMS::$currentPage); - } - - if ( ! is_dir(INC_ROOT . '/uploads')) { - mkdir(INC_ROOT . '/uploads'); - } - - if ( ! move_uploaded_file( - $_FILES['upfile']['tmp_name'], - sprintf(INC_ROOT . '/uploads/%s', - $_FILES['upfile']['name'] - ) - )) { - wCMS::alert('danger', 'Upload: failed to move uploaded file.'); - wCMS::redirect(wCMS::$currentPage); - } - - wCMS::alert('success', 'Upload: file uploaded successfully.'); - wCMS::redirect(wCMS::$currentPage); - } catch (RuntimeException $e) { - wCMS::alert('danger', 'Upload: ' . $e->getMessage()); - wCMS::redirect(wCMS::$currentPage); - } -}