Dropzone.js does not move file to upload folder

i work with dropzone.js plugins, uploadand PHP. I try to use the dropzoneshow success Icon and print the image, but it does not upload my images to the download directory. how can i fix this?

HTML:

<div class="dropzone dropzone-previews" id="my-awesome-dropzone">
  <form action="<?PHP echo SITE.'/controller/'?>upload.php"></form>
  <div class="fallback">
    <input name="file" type="file" multiple />
  </div>
</div>

JS:

<script>
    $(document).ready(function(){
    Dropzone.options.myAwesomeDropzone = { // The camelized version of the ID of the form element
    // The configuration we've talked about above
    url: '<?PHP echo SITE.'/controller/'?>upload.php',
    previewsContainer: ".dropzone-previews",
    uploadMultiple: true,
    parallelUploads: 100,
    maxFiles: 100
  }

 });
</script>

PHP:

<?php
$ds          = DIRECTORY_SEPARATOR;  //1

$storeFolder = '../../uploads/news/';   //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

}
?> 
+4
source share
3 answers

To resolve this issue, two different functions must be performed.

, http://www.startutorial.com/articles/view/how-to-build-a-file-upload-form-using-dropzonejs-and-php, dropzone. , , . AMP / .

, . (, tmp psuedo-, , , . OS/, , .

enctype= multipart/form-data .

, Marc B, , , - . , , , , ( , dropzone.js) CSRF. , :

var unique = "some-unique-string";
var acceptedFileTypes = "image/*"; //dropzone requires this param be a comma separated list

Dropzone.options.myAwesomeDropzone = { 

  // your other settings as listed above
  maxFiles: 10, // allowing any more than this will stress a basic php/mysql stack
  paramName: unique,
  headers: {"MyAppname-Service-Type": "Dropzone"},
  acceptedFiles: acceptedFileTypes

}

PHP, :

  • , , (
  • php, , ( )
  • , php
  • : php $_FILES['file'], , dropzone paramName. &_Files['some-unique-string']
+7

, wirte , !

0

upload.php:


<?php
$upload_dir = 'uploads';
if (!empty($_FILES)) 
{ 
     $tempFile = $_FILES['file']['tmp_name'];//this is temporary server location

     // using DIRECTORY_SEPARATOR constant is a good practice, it makes your code portable.
     $uploadPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $upload_dir . DIRECTORY_SEPARATOR;

     // Adding timestamp with image name so that files with same name can be uploaded easily.
     $mainFile = $uploadPath.time().'-'. $_FILES['file']['name'];

     move_uploaded_file($tempFile,$mainFile);
}

?>
0

All Articles