我试图使用dropzone JS插件和PHP上传多个文件,然后输出每个文件的url。
到目前为止我有这个:
$upload_dir = 'files';
for($i=0; $i<count($_FILES['file']['tmp_name']); $i++) {
$tempFile = $_FILES['file']['tmp_name'][$i];
$uploadPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $upload_dir . DIRECTORY_SEPARATOR;
$mainFile = $uploadPath.time().'-'. $_FILES['file']['name'][$i];
$mainFile_short = time().'-'. $_FILES['file']['name'][$i];
if(move_uploaded_file($tempFile,$mainFile)) {
}
}
不过,我似乎做不到这一点,我不确定哪里出错了。任何想法都很好!
最佳答案
$img = $_FILES['file'];
$upload_dir = 'files';
if(!empty($img))
{
$img_desc = reArrayFiles($img);
print_r($img_desc);
foreach($img_desc as $val)
{
$tempFile = $val['tmp_name'];
$uploadPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $upload_dir . DIRECTORY_SEPARATOR;
$mainFile = $uploadPath.time().'-'. $val['name'];
$mainFile_short = time().'-'. $val['name'];
if(move_uploaded_file($tempFile,$mainFile)) {
}
}
}