我的代码来自:https://github.com/hemantrai88/html5-php_multi-file-upload
我想将其上传到从输入中指定的文件夹。
有人可以帮助我吗?
$input = $_POST["input"];
mkdir('/uploads/'. $input, 0777, true);
if(isset($_REQUEST['AddFiles'])){
$targetFolder = 'uploads/' . $input; //Path to the Uploads Folder
if (!empty($_FILES)) {
for($i=0;$i<count($_FILES['upload_file']['name']);$i++){
$tempFile = $_FILES['upload_file']['tmp_name'][$i];
$targetFile = rtrim($targetFolder,'/') . '/' . $_FILES['upload_file']['name'][$i];
$fileTypes = array('jpeg','jpg','png','gif'); // Allowed File extensions
$fileParts = pathinfo($_FILES['upload_file']['name'][$i]);
if(isset($fileParts['extension'])){
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '<div class="success">'.$_FILES['upload_file']['name'][$i].' was saved successfully inside '.$targetFolder.' Directory</div>';
}else{
echo '<div class="fail">'.$_FILES['upload_file']['name'][$i].' couldn\'t be saved because of invalid file type.</div>';
}
}else{
echo '<div class="fail">'.$_FILES['upload_file']['name'][$i].' couldn\'t be saved because of invalid file type.</div>';
}
}
}
}
答案 0 :(得分:1)
mkdir('/uploads/'. $input, 0777, true);
应该是:
mkdir('uploads/'. $input, 0777, true);
应该有效