@@ -3,13 +3,13 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | use Core\AjaxController; |
| 5 | 5 | |
| 6 | -class ImageUpload extends AjaxController{ |
|
| 6 | +class ImageUpload extends AjaxController { |
|
| 7 | 7 | /** |
| 8 | 8 | * @var string the image upload folder, must be writable |
| 9 | 9 | */ |
| 10 | 10 | private $imageFolder = "uploaded_images/"; |
| 11 | 11 | |
| 12 | - public function tinymceUpload(){ |
|
| 12 | + public function tinymceUpload() { |
|
| 13 | 13 | |
| 14 | 14 | //image uploader for tinymce |
| 15 | 15 | //grabbed from https://www.codexworld.com/tinymce-upload-image-to-server-using-php/ |
@@ -21,26 +21,26 @@ discard block |
||
| 21 | 21 | $tempFile = $this->request->getUploadedFiles(); |
| 22 | 22 | |
| 23 | 23 | //need to clean up |
| 24 | - if(is_uploaded_file($tempFile['tmp_name'])){ |
|
| 24 | + if (is_uploaded_file($tempFile['tmp_name'])) { |
|
| 25 | 25 | // Sanitize input |
| 26 | - if(preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $tempFile['name'])){ |
|
| 26 | + if (preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $tempFile['name'])) { |
|
| 27 | 27 | header("HTTP/1.1 400 Invalid file name."); |
| 28 | 28 | return; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // Verify extension |
| 32 | - if(!in_array(strtolower(pathinfo($tempFile['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "png"))){ |
|
| 32 | + if (!in_array(strtolower(pathinfo($tempFile['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "png"))) { |
|
| 33 | 33 | header("HTTP/1.1 400 Invalid extension."); |
| 34 | 34 | return; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | |
| 38 | - $filetowrite = $this->imageFolder . $tempFile['name']; |
|
| 38 | + $filetowrite = $this->imageFolder.$tempFile['name']; |
|
| 39 | 39 | move_uploaded_file($tempFile['tmp_name'], $filetowrite); |
| 40 | 40 | |
| 41 | 41 | // Respond to the successful upload with JSON. |
| 42 | 42 | echo json_encode(array('location' => $filetowrite)); |
| 43 | - } else { |
|
| 43 | + }else { |
|
| 44 | 44 | // Notify editor that the upload failed |
| 45 | 45 | header("HTTP/1.1 500 Server Error"); |
| 46 | 46 | } |