我遇到了无法上传视频的问题。它产生此错误:无法移动数据。
<?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;
}
}
}
}
答案 0 :(得分:0)
检查这个
$name = "videos/" . $_FILES['filename']['name'];
答案 1 :(得分:0)
视频的目标文件夹看起来很奇怪。
在大多数情况下,//
没问题,但最好只使用一个斜线来分割文件夹。
我还建议使用完整路径,如果我们的PHP文件旁边有videos
,你可以写:
$name = __DIR__.'/videos/'.$_FILES['filename']['name'];
您必须确保PHP有权在文件夹videos
中写入! (您可以使用is_writable()
)
在Windows上你可能需要写\\
(2反斜杠)而不是/
。