Php 将标准形式与Dropzone相结合

Php 将标准形式与Dropzone相结合,php,forms,upload,dropzone.js,Php,Forms,Upload,Dropzone.js,我正在使用dropzone.js创建一个dropzone表单。我首先将表单设置为自动上传文件,效果很好,但我仅在用户提交数据时才调整表单,我添加了名为custom_dropzone.js的文件,表单似乎正常工作,但文件从未上传到文件夹中 HTML代码(index.php) 谢谢你的帮助。我只需要上传文件,其他一切似乎都很好您忘了将enctype='multipart/form data'作为属性添加到中,方法类型为POST 像这样加上 <form id="my-awesome-dropz

我正在使用dropzone.js创建一个dropzone表单。我首先将表单设置为自动上传文件,效果很好,但我仅在用户提交数据时才调整表单,我添加了名为custom_dropzone.js的文件,表单似乎正常工作,但文件从未上传到文件夹中

HTML代码(index.php)


谢谢你的帮助。我只需要上传文件,其他一切似乎都很好

您忘了将
enctype='multipart/form data'
作为属性添加到
中,方法类型为
POST

像这样加上

 <form id="my-awesome-dropzone" method='post' class="dropzone" action="upload.php" enctype='multipart/form-data'>

使用dropzone,您似乎不需要 方法class='post' enctype='multipart/form data' 就像Shankar提到的…但是谢谢你

我通过注释custom_dropzone.js下面的js行来解决这个问题

//uploadMultiple:true,

我试过了,虽然我同意你是正确的,但文件仍然没有上传。感谢您在
upload.php
上对
var\u dump($\u POST)
的任何其他想法,然后看看有什么问题。我之前和刚才都试过了。它不返回任何内容,就好像upload.php文件被完全忽略一样。我只是尝试用绝对路径链接upload文件夹和action=“…但没有帮助。如果我添加自定义js,php函数就会中止
 <!-- Now setup your input fields -->
 <input type="email" name="username" />
 <input type="password" name="password" />

 <button type="submit">Submit data and files!</button>
</form>
</body>
</html> 
<?php
$ds          = DIRECTORY_SEPARATOR;  //1

$storeFolder = '../upload_test/uploads';   //2

if (!empty($_FILES)) {


 $tempFile = $_FILES['file']['tmp_name'];          //3             

 $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;  //4

 $targetFile =  $targetPath. $_FILES['file']['name'];  //5


$allowed =  array('gif','png' ,'jpg');
$filename = $_FILES['file']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) ) {
echo 'error';
}

move_uploaded_file($tempFile,$targetFile); //6

}
?>  
Dropzone.options.myAwesomeDropzone = { // The camelized version of the ID of the form       element

  // The configuration we've talked about above
  autoProcessQueue: false,
  uploadMultiple: true,
  parallelUploads: 3,
  maxFiles: 3,
  previewsContainer: ".dropzone-previews",

  accept: function(file, done) {
    console.log("uploaded");
    done();
   },

  init: function() {
  this.on("maxfilesexceeded", function(file){
    alert("No more files please!");
  });
},

// The setting up of the dropzone
init: function() {
  var myDropzone = this;

  // First change the button to actually tell Dropzone to process the queue.
  this.element.querySelector("button[type=submit]").addEventListener("click",   function(e) {
    // Make sure that the form isn't actually being sent.
    e.preventDefault();
    e.stopPropagation();
    myDropzone.processQueue();
   });

   // Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead
   // of the sending event because uploadMultiple is set to true.
   this.on("sendingmultiple", function() {
  // Gets triggered when the form is actually being sent.
  // Hide the success button or the complete form.
   });
   this.on("successmultiple", function(files, response) {
  // Gets triggered when the files have successfully been sent.
  // Redirect user or notify of success.
  });
  this.on("errormultiple", function(files, response) {
  // Gets triggered when there was an error sending the files.
  // Maybe show form again, and notify user of error
  });
 }

}
 <form id="my-awesome-dropzone" method='post' class="dropzone" action="upload.php" enctype='multipart/form-data'>