HTML PHP上载未上载文件
使用HTML表单将文件发布到PHP并将该文件上载到指定文件夹 PHP返回“成功”,但文件尚未上载。文件夹存在,但没有上载文件 为什么这个文件没有被成功上传 错误检查此行时返回错误HTML PHP上载未上载文件,php,html,upload,Php,Html,Upload,使用HTML表单将文件发布到PHP并将该文件上载到指定文件夹 PHP返回“成功”,但文件尚未上载。文件夹存在,但没有上载文件 为什么这个文件没有被成功上传 错误检查此行时返回错误 foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){ 错误 注意:未定义索引:第21行的scripts/uDoc.php中的文件警告:第21行的scripts/uDoc.php中为foreach提供的参数无效 HTML 看看$desired_d
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
错误
注意:未定义索引:第21行的scripts/uDoc.php中的文件警告:第21行的scripts/uDoc.php中为foreach提供的参数无效 HTML
看看$desired_dir=uDocs;和图像上传/so,您想使用哪个文件夹?您可能需要像move\u upload\u file$file\u tmp、image\u uploads/$desired\u dir/$file\u name;-虽然很难说,但我认为这是您想要使用的。在打开PHP标记后立即在文件顶部添加错误报告,例如注意:未定义索引:第21行的scripts/uDoc.PHP中的文件警告:第21行的scripts/uDoc.PHP中为foreach提供的参数无效$error该变量在ifempty$error中未定义{因此,我确信您打算在$file_type=$\u FILES['FILES']['type'][$key]之后为foreach使用ifempty$errors{您可能还想移动大括号};这是ifempty$error{上面的一个,它将其中的所有内容作为foreach参数。
<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>
$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";
}