2 回答

TA貢獻1830條經驗 獲得超3個贊
您正在嘗試在上傳文件之前處理文件上傳。您必須先檢查表格是否已發布。
<?php
if (isset($_FILES['file'])) {
$allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma");
// $_FILES = $_FILES['file']; // <-- remove this line
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$unique = date('Y-m-d_H-i-s');
if ((null !==($_FILES["file"]["type"] == "video/mp4")
|| (null !==($_FILES["file"]["type"] == "audio/mp3"))
|| ($_FILES["file"]["type"] == "audio/wma")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg"))
&& ($_FILES["file"]["size"] < 2000000)
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
} else {
echo 'File uploaded successfully';
if (file_exists("upload/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
} else {
$datetime = date('Y-m-d_H-i-s');
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploads/" . $_FILES["file"]["name"] . $datetime . md5($_FILES["file"]["name"]));
}
}
} else {
echo "Invalid file";
}
}
?>
<form action="profile.php" id="videoupload" method="post" enctype="multipart/form-data">
<label for="file"><span>Filename:</span></label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

TA貢獻1875條經驗 獲得超3個贊
$_FILES['file']
意味著你有輸入類型=文件名為“文件”。如果您沒有名為“文件”的輸入,則會收到未定義的索引通知。如果你有那個,
$_FILES = $_FILES['file'];
這會給其他代碼帶來錯誤。因為它試圖覆蓋 $_FILES。
- 2 回答
- 0 關注
- 195 瀏覽
添加回答
舉報