PHP中的视频上传,找不到上传目录?

时间:2013-01-30 14:30:01

标签: php video upload

我正在使用这个php视频上传脚本。我已将我的目录路径设置为一个名为video的文件夹,我使用与php文件相同的目录创建该文件夹。但我找不到正在上传的视频。

它没有进入我要求的目录?为什么有人可以帮助我。

我没有收到任何错误。

感谢。

HTML:

<form action="upload_videos_process.php" method="post"   enctype="multipart/form-data">
  <label for="file">Filename:</label>
     <input type="file" name="uploadFile" id="uploadFile" />
<br />
<input type="submit" name="submit" value="Upload File" />
</form>

php文件:

<?php

//This handles the maximum size for the video file in kbs

define ("MAX_SIZE","500");

//This function reads the extension of the file to ensure that it is an video file

function getExtension($str) {

$i = strrpos($str,".");

if (!$i) { return ""; }

$l = strlen($str) - $i;

$ext = substr($str,$i+1,$l);

return $ext;

}

//This variable handles an error and won't upload the file if there is a problem with it

$errors=0;

//checks if the form has been submitted

if(isset($_POST['Submit']))

{

//reads the name of the file the user submitted for uploading

$video=$_FILES['video']['name'];

//if it is not empty

if ($video)

{

//get the original name of the file from the clients machine

$video_filename = stripslashes($_FILES['video']['name']);

$video_extension = getExtension($filename);

$video_extension = strtolower($extension);

//if it is not a known extension, we will suppose it is an error and will not upload the file, otherwise we will do more tests

if (($video_extension != "mpeg") && ($video_extension != "avi") && ($video_extension != "flv") && ($video_extension != "mov"))

{

echo '<h1>Unknown extension!</h1>';

$errors=1;

}

else

{

//get the size of the video

$size=filesize($_FILES['video']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger

if ($size > MAX_SIZE*1024)

{

echo '<h1>You have exceeded the size limit!</h1>';

$errors=1;

}

//give the video a unique name in case a video already exists with the name on the server
$video_name=time().'.'.$extension;

//assign a folder to save the video to on your server

$newname="video/".$video_name;

//verify that the video has been loaded

$copied = copy($_FILES['video']['tmp_name'], $newname);

if (!$copied)

{

echo '<h1>Copy unsuccessful!</h1>';

$errors=1;

}}}}

//If no errors registered, print the success message

if(isset($_POST['Submit']) && !$errors)

{

echo "<h1>File Uploaded Successfully! Try again!</h1>";

}

?>

2 个答案:

答案 0 :(得分:0)

你盲目地认为一切都很完美。事情失败了。第一步:检查上传是否真的做了什么:

if ($_FILES['video']['error'] !== UPLOAD_ERR_OK) {
    die("Upload failed with error code " . $_FILES['video']['error']);
}

错误代码在此处定义:http://php.net/manual/en/features.file-upload.errors.php

同样,在您验证上传成功后,请勿在上传文件中使用copy()。有move_uploaded_file()有一个原因 - 它有额外的安全检查,以确保文件没有被篡改在服务器上,它实际上 MOVES 文件。 copy()可以杀死性能,特别是在大文件上,因为你复制了文件,而不仅仅是做一些文件系统管理。

您还信任用户不要篡改文件名。有 NOTHING 可以阻止恶意用户在上传之前执行ren nastyvirus.exe cutekittens.avi,并且您的脚本会很乐意接受.exe,因为它的文件名只是被更改了。使用服务器端mime-detection(例如http://www.php.net/manual/en/book.fileinfo.php enter link description here)来解决这个问题。 从不信任用户的 ANYTHING

答案 1 :(得分:0)

这可能是因为你的php配置不允许上传大文件。尝试设置

upload_max_filesize = 500M
在php.ini&amp;中

甚至大于500M也正如ppl在评论中提到的那样,启用错误

ini_set('display_errors', 1);
ini_set('error_reporting', 8191);