我遇到無法上傳視頻的問題。它產生這個錯誤:無法移動數據。無法在PHP中移動數據
<?php
//phpunfo();
echo '<br />';
echo <<<_END
<div id = "sec1">
<h1>Video Upload</h1>
<br />
<form method='post' action='Upload.php'
enctype='multipart/form-data'>
Select File: <input type='file' name='filename' size='50' />
<input type='submit' value='Upload' />
</form>
<br />
</div>
_END;
if (isset($_FILES['filename'])) {
$name = "videos//" . $_FILES['filename']['name'];
if (move_uploaded_file($_FILES['filename']['tmp_name'], $name)) {
include 'DO_Files.php';
$file = new DO_File();
$type = $_FILES['filename']['type'];
$size = $_FILES['filename']['size'];
$file->FileName = $name;
$file->FileSize = $size;
$file->Type = $type;
if ($file->save()) {
$fileId = $file->getFileIdFromName();
if ($fileId) {
echo "<h1> Thank you </h1><p>Image stored "
. "successfully</p>";
echo "<p>Upload image '$name'</p><br /><img src='$name' "
. "height='200' width='200'/>";
echo '<br><a href="Display.php?id=' . $fileId .
'">Display image ' . $file->FileName . '</a>';
} else
echo '<p class="error">Error retrieving file '
. 'information</p>';
}
else {
echo '<p class="error"> Oh dear. There was a database '
. 'error</p>';
}
} else {
$error_array = error_get_last();
echo "<p class='error'>Could not move the file</p>";
if (!is_null($error_array)) {
foreach ($error_array as $err) {
echo $err;
}
}
}
}
'$ name =「videos //'在這裏,爲什麼你在路徑中加了兩個'/' – andre3wap
'videos //'?爲什麼是兩個斜槓?並且注意你的代碼是危險的。 ']'in $ _FILES是用戶提供的文件名,並且在他們的控制之下,他們可以輸入路徑信息,導致你的代碼覆蓋你的服務器上的任何文件,測試'isset($ _ FILES)'是毫無意義的。即使上傳失敗也仍然會被設置,你需要檢查'['error']'參數 –