PHP not echoing after file upload completed -


i have simple code upload file using drop zone. it's uploading file fine reason doesn't echo "done uploading" @ end of code.

am missing obvious here?

<script type="text/javascript">   dropzone.options.mydropzone = {     addremovelinks: true,     removedfile: function(file) {        var _ref;       return (_ref = file.previewelement) != null ? _ref.parentnode.removechild(file.previewelement) : void 0;     }   }; </script>  <div id="dropzone">     <form id="mydropzone" action="#" class="dropzone" id="demo-upload">       <div class="dz-message">         drop files here or click upload.<br />       </div>     </form> </div>  <?php $ds = directory_separator;  //1 $storefolder = 'uploads';   //2  if (!empty($_files)) {     $tempfile = $_files['file']['tmp_name'];          //3                  $targetpath = dirname( __file__ ) . $ds. $storefolder . $ds;  //4     $targetfile =  $targetpath. $_files['file']['name'];  //5      move_uploaded_file($tempfile,$targetfile); //6     echo "done uploading"; } ?>   

since dropzone uses ajax post requests server not see response line ordinary php response when echo something.

try in way

<script type="text/javascript">     dropzone.options.mydropzone = {         ...         success: function(file, response){             alert(response); // test, can remove             // want             // like:             if(response == "success") {                 // uploaded ok             } else {                 // failed upload             }         }     }; </script> 

in way after successful ajax request can catch response , whatever want.

ofcoruse, @tftd said, need wrap move_uploaded_file like:

if(move_uploaded_file(...)) {     // done uploading     echo json_encode('success'); } else {     // failed moving     echo json_encode('error'); } 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -