Что означают эти ошибки при попытке загрузить видеофайл? - PullRequest
0 голосов
/ 25 апреля 2019

Ниже приведен мой php-скрипт для загрузки видеофайлов (до 100 МБ) на мой сервер.Проблема в том, что он загружает один файл mp4 без каких-либо проблем.Но когда я пытаюсь загрузить другие, это дает эти ошибкиКогда я пытаюсь загрузить «TJ Hooker (1982) - 1 сезон OPENING.mp4», размером 2,57 МБ, я получаю эту ошибку:

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.Что означает эта ошибка?

Когда я пытаюсь загрузить другой файл "Taekwondo vs Jeet Kune Do.mp4" размером 9,32 МБ, я получаю следующую ошибку:

"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 без ошибок.

1 Ответ

0 голосов
/ 27 апреля 2019

Проблема решена. Файл .ini ограничивал размер файла.

...