如何从单个html表单发布用户名,密码和多个二进制文件并使用php处理它?我不允许使用ajax.
首先在PHP.net上查看这些页面
文件上传信息
move_uploaded_file
但是为了让你开始这里有几个存根文件.
uploadForm.html
processStuff.php
Username & password' echo "Username: {$_POST['username']}\nPassword: {$_POST['password']}"; echo '
'; echo 'Uploaded files
' foreach($_FILES['uploadFile']['tmp_name'] as $i => $tempUploadPath) { if (empty($tempUploadPath)) { // this was "blank"... no file selected } else { // a file was uploaded echo 'A file named "', $_FILES['uploadFile']['name'][$i], "\" was uploaded\n"; echo "\ttemporarily stored at: ", $tempUploadPath, "\n"; echo "\tmime type: ", $_FILES['uploadFile']['type'][$i], "\n"; echo "\tsize: ", $_FILES['uploadFile']['size'][$i], " bytes\n"; echo "\terror code", ((empty($_FILES['uploadFile']['size'][$i]) ? 'no errror' : $_FILES['uploadFile']['size'][$i])), "\n\n"; // do something useful with the uploaded file // access it via $tempUploadPath and use move_uploaded_file() to move // it out of the temp path before you manipulate it in any way!!!!! // see http://us3.php.net/features.file-upload // and http://us3.php.net/manual/en/function.move-uploaded-file.php } } ?>
这个HTML文件显示如何设置enctype
的与第二种形式告诉您如何访问提交的用户名和密码及最后如何环路直通每个上传的文件.
如上所述,您必须尽快移动文件.它们被上传到临时位置,系统将删除它们,除非您处理它们.所以先把它们移到某个地方,然后随心所欲地做任何事情.
这有帮助
阿林