I'm encountering a problem where I can't upload my videos. It produce this error: Could not move data.
<?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;
}
}
}
}
check this
$name = "videos/" . $_FILES['filename']['name'];
The destination folder for your video looks strange.
In most cases a //
in no problem, but it would be better to use only one slash to divide folders.
I also would recommend to use a full path, if videos
is next to our PHP file, you can write:
$name = __DIR__.'/videos/'.$_FILES['filename']['name'];
And you have to make sure that PHP has the rights to write in the folder videos
! (You can check this with is_writable()
)
On windows you maybe have to write \\
(2 backslash) instead of /
.