以下是我的php脚本,可用于将视频文件(最大100MB)上传到我的服务器。 问题是,它可以毫无问题地上传一个mp4文件。但是,当我尝试上传其他文件时,会出现这些错误。 当我尝试上传2.57MB的“ T.J. Hooker(1982)-第1季OPENING.mp4”时,出现此错误:
array(1) { ["id_verification_video_file"]=> array(5) { ["name"]=>
string(41) "T.J. Hooker (1982) - Season 1 OPENING.mp4" ["type"]=>
string(0) "" ["tmp_name"]=> string(0) "" ["error"]=> int(1) ["size"]=>
int(0) } } Array ( [id_verification_video_file] => Array ( [name] => T.J.
Hooker (1982) - Season 1 OPENING.mp4 [type] => [tmp_name] => [error] => 1
[size] => 0 ) )
Q1。这个错误是什么意思?
当我尝试上传9.32MB的另一个文件“跆拳道与Jeet Kune Do.mp4”时,出现以下错误:
“ array(0){}上传您的视频文件”。
Q2。为什么在尝试上传视频(mp4)文件时触发第17行?
第17行:
if(!isset($_FILES["id_verification_video_file"]))
{
echo "Upload your video file";
exit;
}
完整脚本:
<?php
$conn = mysqli_connect("localhost","livefoll_user","livefollow_2019*","livefoll_live
follow");
if (!$conn)
{
$error = mysqli_connect_error();
$errno = mysqli_connect_errno();
print "$errno: $error\n";
exit();
}
if($_SERVER["REQUEST_METHOD"] == "POST")
{
var_dump($_FILES);
//Check whether the file was uploaded or not without any errors.
if(!isset($_FILES["id_verification_video_file"]))
{
echo "Upload your video file";
exit;
}
elseif (!$_FILES["id_verification_video_file"]["error"] == 0)
{
$Errors = Array();
$Errors[] = "Error: " . $_FILES["id_verification_video_file"] ["ERROR"]; print_r($_FILES); ?><br><?php
print_r($_ERRORS);
exit();
}
else
{
$user = 'livefoll_user';
//Feed Id Verification Video File Upload Directory path.
$directory_path = 'uploads/videos/id_verifications/';
//Make Directory under $user in 'uploads/videos/id_verifications' Folder.
$directory_path_and_user_dir = "uploads/videos/id_verifications/$user";
if(!is_dir($directory_path_and_user_dir))
{
$user = 'livefoll_user';
$mode = 0755;
mkdir($directory_path_and_user_dir,$mode, TRUE);
}
//Grab Uploading File details.
$Errors = Array(); //
$file_name = $_FILES["id_verification_video_file"]["name"];
$file_tmp = $_FILES["id_verification_video_file"]["tmp_name"];
$file_type = $_FILES["id_verification_video_file"]["type"];
$file_size = $_FILES["id_verification_video_file"]["size"];
$file_error = $_FILES['id_verification_video_file']['error'];
//Grab Uploading File Extension details.
$file_extension = pathinfo($file_name, PATHINFO_EXTENSION);
$directory_path_and_user_dir_and_user_file = "$directory_path_and_user_dir/$file_name";
if(file_exists($directory_path_and_user_dir_and_user_file)) //THIS LINE IS NOT GIVING THE ERROR THAT FILE ALREADY EXISTS. INSTEAD SHOWING A BLANK WHITE PAGE. -> I changed it with 'echo'. It was not giving error because you were just storing the error into the Errors array without throwing the error.
{
echo "Error: You have already uploaded a video file to verify your ID! No need to upload and do it again!";
exit();
}
else
{
//Feed allowed File Extensions List.
$allowed_file_extensions = array("mp4" => "video/mp4");
//Feed allowed File Size.
$max_file_size_allowed_in_bytes = 1024*1024*100; //Allowed limit: 100MB.
$max_file_size_allowed_in_kilobytes = 1024*100; //Allowed limit: 100MB.
$max_file_size_allowed_in_megabytes = 100; //Allowed limit: 100MB.
$max_file_size_allowed = "$max_file_size_allowed_in_bytes";
//Verify File Extension.
if(!array_key_exists($file_extension, $allowed_file_extensions))
{
echo "Error: Select a valid video file format. Select an Mp4, Wav, etc. files.";
exit();
}
//Verify MIME Type of the File.
elseif(!in_array($file_type, $allowed_file_extensions))
{
$Errors[] = "Error: There was a problem uploading your file $file_name! Make sure your file is a video file. You may try again."; //IS THIS LINE CORRECT ? -> yes but won't print if you don't use throwerror or echo ... echo "error: there was a problem... etc..."
exit();
}
//Verify File Size. Allowed Max Limit: 100MB.
elseif($file_size>$max_file_size_allowed)
{
$Errors[] = "Error: Your Video File Size is larger than the allowed limit of: $max_file_size_allowed_in_megabytes.";
exit();
}
$move_to = $directory_path_and_user_dir."/".$file_name;
//Move uploaded File to newly created directory on the server.
if(!move_uploaded_file($file_tmp, $move_to))
{
//user = 'livefoll_user'; //Not necessary
$mode = 0755; //Not necessary
//Notify user their Id Verification Video File uploading failed.
echo "Your Video File \"$file_name\" has failed to be uploaded! You may try some other time.";
exit();
}
else
{
//Notify user their Id Verification Video File was uploaded successfully.
die("Your Video File \"$file_name\" has been uploaded successfully!");
}
}
}
}
?>
<?php //SWITCH FOLLOWING UPLOADING WEB FORM TO HTML5 DESIGN WITH CAPTCHA
AND HIDDEN FIELD/S. FOIL BOTS FROM UPLOADING FILES. MUST BE SQL INJECTION
AND HACKING PROOF.?>
<form METHOD="POST" ACTION="" enctype="multipart/form-data">
<fieldset>
<p align="left"><h3><?php $site_name ?> ID Video Verification
Form</h3></p>
<div class="form-group">
<p align="left"<label>Video File: </label>
<input type="file" name="id_verification_video_file"
id="id_verification_video_file" value="uploaded 'Id Verification Video
File.'"></p>
</div>
</fieldset>
<p align="left"><button type="submit" class="btn btn-default"
name="id_verification_video_file_submit">Submit!</button></p>
</form>
</body>
</html>
Q4。如何解决这些问题?我的意思是,如果脚本代码没有错误,并且能够上传一个mp4文件,那么它也应该能够上传其他mp4文件而不会显示错误。
答案 0 :(得分:0)
问题解决了。 .ini文件限制了文件大小。