我一直在試圖將文件上傳到服務器但我得到未定義的索引錯誤,如下圖所示:上載音頻未定義指數 - WAMP
Notice: Undefined index: uploadFile in D:\test\getfile.php on line 7
Notice: Undefined index: uploadFile in D:\test\getfile.php on line 8
這是我的index.php:
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
This form allows you to upload a file to the server.<br>
<form action="getfile.php" method="post"><br>
Type (or select) Filename: <input type="file" name="uploadFile">
<input type="submit" value="Upload File">
</form>
</body>
這是getfile.php:
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}")
?>
</body>
我把他從另一個網站的代碼。這在他們的服務器上工作。
這是wamp。
*總是*檢查密鑰是否實際存在使用例如。 'if(isset($ _ FILES ['uploadFile'])){}'。還應該補充一點,我希望你在'/ uploads /'中禁用執行,否則任何人都可以簡單地上傳一個PHP shell並破解整個服務器 - 獲取你的代碼 - 獲取你的數據庫證書 - 安裝病毒 - 獲取用戶密碼等等 – h2ooooooo
@ h2ooooooo這只是測試。我試圖找出爲什麼它不工作。 – Efekan
Ok point1 rtfm http://www.php.net/manual/en/features.file-upload.php。複製代碼可以讓你開始,但最終你會得到和最後一個懶惰人一樣的垃圾。在代碼中正確的文件上傳還有很多。 – RiggsFolly