我在为多个文件上传实现此脚本时遇到问题。用户需要准确指定将文件放入的文件夹(课程代码),因此 $_POST 函数
这是我的 HTML
<form enctype="multipart/form-data" action="uploader.php" method="POST">
Choose Course Code:
<select name="subject_list">
<option value="ACC 100">ACC 100</option>
<option value="ACC 406">ACC 406</option>
<option value="ECN 104">ECN 104</option>
<option value="ECN 204">ECN 204</option>
<option value="FIN 300">FIN 300</option>
<option value="GMS 200">GMS 200</option>
<option value="ITM 100">ITM 100</option>
<option value="ITM 301">ITM 301</option>
<option value="ITM 305">ITM 305</option>
<option value="ITM 330">ITM 330</option>
<option value="ITM 350">ITM 350</option>
<option value="ITM 407">ITM 407</option>
<option value="ITM 500">ITM 500</option>
<option value="ITM 501">ITM 501</option>
<option value="ITM 505">ITM 505</option>
<option value="ITM 600">ITM 600</option>
<option value="LAW 122">LAW 122</option>
<option value="SSH 105">SSH 105</option>
<option value="Other">Other</option>
</select>
<br>
Choose a file to upload (Max 500MB): <input name="rye_file[]" type="file" id="file_style" multiple />
<input type="submit" name="submit" value="Upload" />
</form>
<form action="/logout.php">
<input type="submit" value="Logout">
</form>
这是我的PHP:
<?php
session_start();
// IF USER NOT REMEMBERED(DID NOT CLICK REMEBER ME BUTTON) OR NO SESSION IS FOUND THEN THROW HIM OUT TO LOGIN
//SECURITY SO THAT USERS CANT ACCESS WEB URL DIRECTLY
if (!isset($_SESSION['myusername']) && !isset($_COOKIE['myusername'])) {
header("Location: index.php");
}
// SUBJECT_LIST IS FOR USER TO CHOOSE FOLDER
$subject_list = $_POST['subject_list'];
$uploaddir = "/var/www/fixnode_website/content/Secure Login/Rye High/uploads/$subject_list";
$files=array();
$fdata=$_FILES['rye_file'];
if(is_array($fdata['name'])){
for($i=0;$i<count($fdata['name']);++$i){
$files[]= array(
'name' => $fdata['name'][$i],
'tmp_name' => $fdata['tmp_name'][$i],
);
}
} else $files[]=$fdata;
foreach ($files as $file) {
// uploaded location of file is $file['tmp_name']
// original filename of file is $file['name']
if (move_uploaded_file($file['tmp_name'], "$uploaddir/$file['name']")) {
echo "File is valid, and was successfully uploaded.\n Please wait, your browser will refresh in 5-10 seconds!";
} else {
echo "Upload failed";
}
}
?>
我不断收到错误 500 服务器错误。如果有人可以帮助修改我的代码以匹配我的参数,那么我将不胜感激
谢谢,菲利普·库贾瓦