Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    757
    Rep Power
    0

    Question Why Undefined Index Error And Not Default File Type Error ?


    Php Folks,

    Why do I keep getting this error and how to solve it ?
    Notice: Undefined index: video_verification_file in C:\xampp\htdocs\test\upload.php on line 33

    Trying to build a web form where you submit your img file. You should get error if the file is not img file. I tried uploading .php file to see if I get the default error alert or not but ain;t getting it.
    Default error:

    Error: Please select a valid file format.

    PHP Code:
    <?php 

    // Check if the form was submitted
    if($_SERVER["REQUEST_METHOD"] == "POST"){
        
    // Check if file was uploaded without errors
        
    if(isset($_FILES["video_verification_file"]) && $_FILES["video_verification_file"]["error"] == 0){
            
    $allowed = array("jpg" => "image/jpg""jpeg" => "image/jpeg""gif" => "image/gif""png" => "image/png");
            
    $filename $_FILES["video_verification_file"]["name"];
            
    $filetype $_FILES["video_verification_file"]["type"];
            
    $filesize $_FILES["video_verification_file"]["size"];
        
            
    // Verify file extension
            
    $ext pathinfo($filenamePATHINFO_EXTENSION);
            if(!
    array_key_exists($ext$allowed)) die("Error: Please select a valid file format.");
        
            
    // Verify file size - 5MB maximum
            
    $maxsize 1024 1024;
            if(
    $filesize $maxsize) die("Error: File size is larger than the allowed limit.");
        
            
    // Verify MYME type of the file
            
    if(in_array($filetype$allowed)){
                
    // Check whether file exists before uploading it
                
    if(file_exists("upload/" $_FILES["video_verification_file"]["name"])){
                    echo 
    $_FILES["video_verification_file"]["name"] . " is already exists.";
                } else{
                    
    move_uploaded_file($_FILES["video_verification_file"]["tmp_name"], "upload/" $_FILES["video_verification_file"]["name"]);
                    echo 
    "Your file was uploaded successfully.";
                } 
            } else{
                echo 
    "Error: There was a problem uploading your file. Please try again."
            }
        } else{
            echo 
    "Error: " $_FILES["video_verification_file"]["error"];
        }
    }

        
    ?>
        
    <form method="post" action="">    
        <fieldset>    
        <p align="left"><h3><?php $site_name ?> Video Verification Form</h3></p>
        <div class="form-group">
            <p align="left"><label>Video File:</label>
            <input type="file" name="video_verification_file" id="video_verification_file" value ="Upload Image"></p>
        </div>    
        </fieldset>    
        <p align="left"><button type="video_verification_submit" class="btn btn-default" name="video_verification_submit">Submit!</button></p>
    </form>
    </body>
    </html>
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,932
    Rep Power
    4554
    If you did what it says here, I think you'd be off to a better start: PHP: POST method uploads - Manual

    Let's pretend like you know what you're doing and you tell me what condition is failing in order for you to see the error message on line 33.
    -- Cigars, whiskey and wild, wild women. --
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    757
    Rep Power
    0
    Originally Posted by Sepodati
    If you did what it says here, I think you'd be off to a better start: PHP: POST method uploads - Manual

    Let's pretend like you know what you're doing and you tell me what condition is failing in order for you to see the error message on line 33.
    Thanks SedoPati!
    I'll check it out tomorrow! I hope the link will teach me how to get uploaded video files (mp4 etc.). I think it will as it seems to be teaching how to upload binary files. Just had a quick glance. As for now: GOOD NIGHT!

    EDIT: SO, I was getting the error as I was not uploading img file ?
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,932
    Rep Power
    4554
    Let's pretend like you know what you're doing and you tell me what condition is failing in order for you to see the error message on line 33.
    -- Cigars, whiskey and wild, wild women. --
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    757
    Rep Power
    0
    Originally Posted by Sepodati
    Let's pretend like you know what you're doing and you tell me what condition is failing in order for you to see the error message on line 33.
    Why don't we stop pretending I know what I am doing and pretend (oops! KNOW) what you claim to know and see how well you spotted my mistake ? I won't know unless you tell me. Now, will I ?

    EDIT: You mean, I missed this part ? ....

    <form enctype="multipart/form-data"


    Anyway, reading your given link now.

    UPDATE: Yeah, I fixed the form and I get the required error as expected when I try uploading file with wrong extension.
    Now, need to switch the following to procedural type from oop:

    PHP Code:
    $allowed = array("mp4"); 
    Doing it like this:

    PHP Code:
    $allowed = array("jpg" => "image/jpg""jpeg" => "image/jpeg""gif" => "image/gif""png" => "image/png"); 
    And so, let's pretend I don't know what I'm doing and let's pretend you will come to the rescue like a good boy.
    Last edited by UniqueIdeaMan; January 26th, 2018 at 04:03 AM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    757
    Rep Power
    0
    Ok, here is my latest update:

    PHP Code:
    <?php 

    // Check if the form was submitted
    if($_SERVER["REQUEST_METHOD"] == "POST"){
        
    // Check if file was uploaded without errors
        
    if(isset($_FILES["video_verification_file"]) && $_FILES["video_verification_file"]["error"] == 0){
            
    $allowed = array("mp4" => "upload/mp4");
            
    $filename $_FILES["video_verification_file"]["name"];
            
    $filetype $_FILES["video_verification_file"]["type"];
            
    $filesize $_FILES["video_verification_file"]["size"];
        
            
    // Verify file extension
            
    $ext pathinfo($filenamePATHINFO_EXTENSION);
            if(!
    array_key_exists($ext$allowed)) die("Error: Please select a valid file format.");
        
            
    // Verify file size - 1000GB maximum
            
    $maxsize 1024 1024 1024 1024 1024;
            if(
    $filesize $maxsize) die("Error: File size is larger than the allowed limit.");
        
            
    // Verify MYME type of the file
            
    if(in_array($filetype$allowed)){
                
    // Check whether file exists before uploading it
                
    if(file_exists("upload/" $_FILES["video_verification_file"]["name"])){
                    echo 
    $_FILES["video_verification_file"]["name"] . " is already exists.";
                } else{
                    
    move_uploaded_file($_FILES["video_verification_file"]["tmp_name"], "upload/" $_FILES["video_verification_file"]["name"]);
                    echo 
    "Your file was uploaded successfully.";
                } 
            } else{
                echo 
    "Error: There was a problem uploading your file. Please try again."
            }
        } else{
            echo 
    "Error: " $_FILES["video_verification_file"]["error"];
        }
    }

        
    ?>
        
    <form enctype="multipart/form-data" action="" method="POST">
        <fieldset>    
        <p align="left"><h3><?php $site_name ?> Video Verification Form</h3></p>
        <div class="form-group">
            <p align="left"><label>Video File:</label>
            <input type="file" name="video_verification_file" id="video_verification_file" value ="Uploaded Video Id"></p>
        </div>    
        </fieldset>    
        <p align="left"><button type="video_verification_submit" class="btn btn-default" name="video_verification_submit">Submit!</button></p>
    </form>
    </body>
    </html>
    Why do I get these errors ? Note that, my file size for experimenting purpose put it to 1000GB. And so, I should not be getting the first error!

    Warning: POST Content-Length of 79117293 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

    Notice: Undefined index: video_verification_file in C:\xampp\htdocs\test\upload.php on line 33
    Error:


    Line 33 looks like this:

    PHP Code:
    } else{
            echo 
    "Error: " $_FILES["video_verification_file"]["error"]; 
    It is related to this IF on line 6:
    PHP Code:
    if(isset($_FILES["video_verification_file"]) && $_FILES["video_verification_file"]["error"] == 0){ 
    What do you reckon is wrong ?
  12. #7
  13. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,932
    Rep Power
    4554
    Originally Posted by UniqueIdeaMan
    let's pretend I don't know what I'm doing
    There's no need to pretend in this case.
    -- Cigars, whiskey and wild, wild women. --
  14. #8
  15. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,932
    Rep Power
    4554
    Let's pretend that English is at least your second language. What does this message say to you? (It's a warning, not an error, as it clearly says.)

    Warning: POST Content-Length of 79117293 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
    -- Cigars, whiskey and wild, wild women. --
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    757
    Rep Power
    0
    Originally Posted by Sepodati
    Let's pretend that English is at least your second language. What does this message say to you? (It's a warning, not an error, as it clearly says.)

    Warning: POST Content-Length of 79,117,293 bytes exceeds the limit of 8,388,608 bytes in Unknown on line 0
    I thought it was talking about the file size. Is it not ? So, 8MB is the content limit (or file size limit) and the file I tried uploading is 79MB. So, if I understood that right then what makes ya a-think I a gaaat it raang ? Aaaand, my Hwat makes ya Tink EngaaLisshh is my secondAA langueeze ?
    My point is, I should not be getting this WARNING since my file size limit on php side is 1000GB.

    PHP Code:
    // Verify file size - 1000GB maximum
            
    $maxsize 1024 1024 1024 1024 1024
    Hang on a SEC, leMME checkaaaa' Hwaat the column size is in my mysql tbl. SomethingsA ringgggingAA bell. Or, should I say: "Beww" ?

    EDIT: Actually, I'm trying to upload it to my c drive (testing on xamp). No mysql tbl.
    Last edited by UniqueIdeaMan; January 26th, 2018 at 09:14 AM.
  18. #10
  19. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,932
    Rep Power
    4554
    What makes you think "in Unknown on line 0" has anything to do with your ****ty code on line <whatever>?
    -- Cigars, whiskey and wild, wild women. --
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    757
    Rep Power
    0
    Originally Posted by Sepodati
    What makes you think "in Unknown on line 0" has anything to do with your ****ty code on line <whatever>?
    Quite frankly my fellow American, I was wondering what the heck it means by line "0". I am still puzzled about it. So, what's the big mystery, my maaan ?
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2017
    Posts
    757
    Rep Power
    0
    Sepodati,

    Wait a sec. Usually, the WARNING or the ERROR points-out the path to the php file that is giving the error. Like " in test/file.php". In this case, the file path is missing and substituted with "Unknown".
    Is the error (Ooops! WARNING) telling me there is something wrong with my indication to it of my file path or directory path ?

    EDIT: Btw, I won't take you seriously any more when you say my code is "s**t*" because this code is from the following link. And if you think their code is **** then that means you'll call all my code **** no matter where they come from. Even if they come from you and you forgot about them.
    https://www.tutorialrepublic.com/php...ile-upload.php
    Last edited by UniqueIdeaMan; January 31st, 2018 at 08:19 AM.
  24. #13
  25. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,932
    Rep Power
    4554
    I'd hardly call it a mystery when you can type the first few words of the warning message, or the entire message itself, into Google and the first response shows you why you encounter the problem and how to fix it.

    You do know how you use search engines, right? Since you are, lol, "creating" one?
    -- Cigars, whiskey and wild, wild women. --
  26. #14
  27. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,932
    Rep Power
    4554
    Originally Posted by UniqueIdeaMan
    Wait a sec.
    Two ****ing days later and you finally read the goddamn warning message. Congrats!
    -- Cigars, whiskey and wild, wild women. --
  28. #15
  29. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,932
    Rep Power
    4554
    The code you copy and paste is fine, for the most part. If it were written better, you wouldn't be getting the second NOTICE message at all, though. There's a logic flaw there.

    The **** part comes when you get your ****beaters on the code. What the hell is a file type of "upload/mp4"? Do you know the difference between bytes and bits? Between 8Mb and 8MB?
    -- Cigars, whiskey and wild, wild women. --
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo