我試圖從HTML表單上傳文件,以便文件轉到特定文件夾,並將路徑上傳到數據庫。 數據庫部分工作正常,但文件不去我的目標文件夾。 我將文件夾權限設置爲777,並在我的php.ini文件file_uploads = on中。無法將文件上傳到服務器文件夾
<?php
require 'config.php';
$connection = new mysqli($servername, $username, $password, $db);
foreach ($_FILES['upload']['name'] as $key => $name) {
if(move_uploaded_file($_FILES['upload']['name'][$key], '/upload_test/' .
$name)){
echo "Uploaded";
} else {
echo "Debug ", print_r($_FILES);
};
$path = '/upload_test/' . $name;
mysqli_query($connection, "insert into docs (path) values ('$path')");
}
?>
<script src="addInput.js" type="text/javascript"></script>
<form method="POST" action="upload.php" enctype="multipart/form-data">
<div id="dynamicInput">
<input type="file" name="upload[]" multiple><input type="button"
value="+" onClick="addInput('dynamicInput');">
</div>
<input type="submit" value="Upload">
</form>
當我試圖把它上傳返回此:
Debug: Array(
[upload] => Array(
[name] => Array([0] => test.docx)
[type] => Array([0] => application/vnd.openxmlformats-officedocument.wordprocessingml.document)
[tmp_name] => Array([0] => /tmp/phputnLek)
[error] => Array([0] => 0)
[size] => Array([0] => 12551)
)
)
的可能的複製[如何獲得用foreach鍵值?](https://stackoverflow.com/questions/3418628/how- to-get-key-values-with-foreach) – Twinfriends
上傳目錄是否真的位於文件系統的根目錄? – jeroen
你是什麼意思的文件系統的根?所有文件都在一個文件夾/ multiple_file_upload中。有腳本。上傳文件夾在這個內部:/ multiple_file_upload/upload_test – Serrano