0

I am using Dropzone.js for my website and am getting stuck on sending a response through server side.
This is my code.
upload.php

<?php
header("Content-Type:application/json");
$target_dir = '../assets/uploads/';
$target_file = $target_dir . basename($_FILES['filetoupload']['name']);
$imagetype = strtolower(pathinfo($target_file , PATHINFO_EXTENSION));
$sizeoffile = $_FILES['filetoupload']['size'];
if( $sizeoffile > 3000000){
    $response = 'File is Too Big. Max 3MB !';
    $status = 417;
    goto respond;
}
else{
    $response = 'checking';
    $status = 200;
    goto respond;
}
respond:
$data = array(
    'status' => $status,
    'responseText' => $response ,
    'size' => $sizeoffile
);
echo json_encode($_FILES);//just for checking
?>   

uploader.js

var myDropzone = new Dropzone('#myDropZone',{
    /* ... */
    init: function(){
         this.on("success", function(file, response){
         console.log(file);
         console.log(response);
        });
        } 
 });

The JSON response from the server side to javascript on console looks like this. Have a look at this.
Thanks for any help!

While if I choose an image of size less than 2Mb It is working
This is another image have a look

Dheeraj
  • 125
  • 2
  • 9
  • What is `error:1` (in the first image, and it's better to not post images as links) if it's the PHP error `The uploaded file exceeds the upload_max_filesize directive in php.ini.` Then you need to increase that and `post_max_size` see: https://stackoverflow.com/questions/2184513/change-the-maximum-upload-file-size – ArtisticPhoenix Aug 19 '18 at 19:52

1 Answers1

0

based on your linked images (better to just post as text)

The first one says error:1 in PHP this is

The uploaded file exceeds the upload_max_filesize directive in php.ini.

PHP's common default is maximum 2 MB upload file size

While if I choose an image of size less than 2Mb It is working

These two things lead me to believe you need to increase the upload size:

 upload_max_filesize 
 post_max_size 

Both of which can be found in the php.ini configuration file for PHP. I usually set this to about 80M right off the bat, anything much more then that and you should be using something like FTP for the uploads.

you may also run into issues with the max execution time limit. But that is a question for another post.

ArtisticPhoenix
  • 21,464
  • 2
  • 24
  • 38