Warning: getimagesize() [function.getimagesize]: Filename cannot be empty warning message?

前端 未结 6 1971
野的像风
野的像风 2020-12-06 15:37

Up until recently I\'ve been using some PHP to upload photos to a site. But suddenly it\'s started triggering all sorts of error messages.

I use a form that on actio

相关标签:
6条回答
  • 2020-12-06 15:47

    you should change the form enctype to "multipart/form-data"

    <form method="post" enctype="multipart/form-data">
         ....
    </form>
    
    0 讨论(0)
  • 2020-12-06 15:51

    After you upgrade 'upload-max-filesize' , Restart all Services of wamp or xampp ! it will right !

    0 讨论(0)
  • 2020-12-06 15:54

    Notice: Undefined index: fileToUpload in D:\xampp\htdocs\public_html\php\form_php\application\process_application.php on line 38

    Notice: Undefined index: fileToUpload in D:\xampp\htdocs\public_html\php\form_php\application\process_application.php on line 43

    Warning: getimagesize(): Filename cannot be empty in D:\xampp\htdocs\public_html\php\form_php\application\process_application.php on line 43 File is not an image.Sorry, file already exists. Notice: Undefined index: fileToUpload in D:\xampp\htdocs\public_html\php\form_php\application\process_application.php on line 58 Sorry, only JPG, JPEG, PNG & GIF files are allowed.Sorry, your file was not uploaded.

    If You Get Errors like this one you should check you have added form enctype to "multipart/form-data"

    <form method="post" enctype="multipart/form-data">
         ....
    </form>
    

    Use to catch me out quite a lot to begin with.

    0 讨论(0)
  • 2020-12-06 15:58

    Change these parameters in your php.ini file; (Currently it allow only 2Mb size to upload and post). Sometimes it's reason for these errors.

    upload_max_filesize = 500M
    post_max_size = 500M
    max_execution_time = 120
    
    0 讨论(0)
  • 2020-12-06 16:02

    Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in

    Verify the MAX_SIZE variable, example to define it for a 2Mo image:

    define('MAX_SIZE', 2000000);
    <form enctype="multipart/form-data" method="post" action="upload.php">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_SIZE; ?>" /> 
    <input name="fichier" type="file" id="fichier_a_uploader" /> <br>
    <input type="submit" name="submit" value="Uploader" /> 
    </form>

    you can also verify the Maximum size of POST data that PHP will accept and Maximum allowed size for uploaded files in PHP.ini : post_max_size = ? upload_max_filesize = ?

    0 讨论(0)
  • 2020-12-06 16:08

    You checked if the form was submitted, but didn't check if the file was sent. In some cases, a form could be submitted but the file will not sent (i.e. file size is bigger then file size limit in config).

    Use this:

    if(isset($_POST["submit"]) && isset($_FILES['file'])) {
        $file_temp = $_FILES['file']['tmp_name'];   
        $info = getimagesize($file_temp);
    } else {
        print "File not sent to server succesfully!";
        exit;
    }
    

    You see && isset($_FILES['file']) is new

    Or you can extend it

    if(isset($_POST["submit"]) && isset($_FILES['file'])) {
        $file_temp = $_FILES['file']['tmp_name'];   
        $info = getimagesize($file_temp);
    } 
    elseif(isset($_POST["submit"]) && !isset($_FILES['file'])) {
        print "Form was submitted but file wasn't send";
        exit;
    }
    else {
        print "Form wasn't submitted!";
        exit;
    }
    
    0 讨论(0)
提交回复
热议问题