使用HTML表单将文件发布到PHP并将该文件上载到指定的文件夹。
PHP正在返回“成功”但该文件尚未上传。该文件夹存在,但没有文件上传。
Q. Why is this file not being successfully uploaded?
错误检查此行时会返回错误
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
错误 注意:未定义的索引:第21行的脚本/ uDoc.php中的文件警告:在第21行的脚本/ uDoc.php中为foreach()提供的参数无效
HTML
<form id='licenseForm' method='POST' action='scripts/uDoc.php' enctype="multipart/form-data">
<input type='file' name="files" id='license_upload_btn' />
<input type='hidden' name='uid' value='{member_id}' />
<input type='hidden' name='docType' value='license' />
</form>
PHP
$errors= array();
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$file_name = $key.$_FILES['files']['name'][$key];
$file_size =$_FILES['files']['size'][$key];
$file_tmp =$_FILES['files']['tmp_name'][$key];
$file_type=$_FILES['files']['type'][$key];
$desired_dir="uDocs";
if(empty($errors)==true){
if(is_dir($desired_dir)==false){
mkdir("$desired_dir", 0700);// Create directory if it does not exist
}
if(is_dir("$desired_dir/".$file_name)==false){
move_uploaded_file($file_tmp,"image_uploads/".$file_name);
}else{ //rename the file if another one exist
$new_dir="image_uploads/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
}else {
print_r($errors);
}
}
if(empty($error)){
echo "Success";
}