我有一个带有多浏览字段的前端表单(ajax提交)。我们如何在php中读取浏览的文件并将文件保存到指定的文件夹中。
我已提到此链接。但是没有在pp函数中获取浏览的文件数据 How to upload multiple files using PHP, jQuery and AJAX
请参阅脚本:
var formData = new FormData(jQuery(this).parents('form')[0]);
jQuery.ajax({
url: "<?php echo Mage::getUrl('a/b/c'); ?>",
type: 'POST',
xhr: function() {
var myXhr = jQuery.ajaxSettings.xhr();
return myXhr;
},
success: function (data) {
alert("Data Uploaded: "+data);
},
data: formData,
cache: false,
contentType: false,
processData: false
});
这是我的php功能:
public function fileuploadAction() {
Mage::log('ghj'.count($_POST['file']['name']), null, '107171.log');
Mage::log($this->getRequest()->getPost(), null, '107172.log');
for($i=0; $i<count($_FILES['file']['name']); $i++){
$target_path = "uploads/";
$ext = explode('.', basename( $_FILES['file']['name'][$i]));
$target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext)-1];
if(move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {
echo "The file has been uploaded successfully <br />";
} else{
echo "There was an error uploading the file, please try again! <br />";
}
}
该功能未进入循环。也算($ _ POST ['file'] ['name'])记录0。
如何在函数中读取此表单数据?请帮忙。提前谢谢。