0

我正在使用这个 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>";

}

?>
4

2 回答 2

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()是有原因的——它有额外的安全检查来确保文件没有在服务器上被篡改,并且它实际上移动了文件。copy() 会降低性能,尤其是在大文件上,因为您正在复制文件,而不是仅仅做一些文件系统内务处理。

您还相信用户不会篡改文件名。在上传之前没有什么可以阻止恶意用户做的事情ren nastyvirus.exe cutekittens.avi,而且你的脚本会很高兴地接受那个 .exe,因为它的文件名只是被改变了。使用服务器端 mime-detection(例如http://www.php.net/manual/en/book.fileinfo.php在此处输入链接描述)来解决这个问题。永远不要相信来自用户的任何东西。

于 2013-01-30T14:35:58.340 回答
0

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

upload_max_filesize = 500M

甚至在 php.ini 中大于 500M 并且正如 ppl 在评论中提到的那样,启用错误

ini_set('display_errors', 1);
ini_set('error_reporting', 8191); 
于 2013-01-30T14:41:05.800 回答