1
votes

I've got a formular in which users should upload an image with a specific dimension and type. When I select an image and click on the submit button, a warning comes up:

Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in xxx.php on line 5

The code to check dimensions and type isn't necassary for this issue.

<!-- language: lang-php -->
<?php
    if (isset($_POST["submit"])) {
        list($width, $height, $type, $attr) = getimagesize($_FILES["image"]["name"]);       
    } else { ?>

    <form action="#" method="post" enctype="multipart/form-data">
        <input type="file" name="image" />
        <input type="submit" name="submit" />
    </form>             
<?php } ?>
3

3 Answers

2
votes

Use $_FILES["image"]["tmp_name"] instead of $_FILES["image"]["name"].

0
votes

You need to put the tmp file in there, not the file name;

 list($width, $height, $type, $attr) = getimagesize($_FILES["image"]["tmp_name"]);    
0
votes

In the block below, you should not be checking for just $_POST, but also for the presence of $_FILES. It seems like you aren't successfully sending your file to the server.

if(isset($_POST["submit"])) {

    list($width, $height, $type, $attr) = getimagesize($_FILES["image"]["tmp_name"]);       

}

EDIT: As pointed out by other answers, you should also be using "tmp_name" instead of name.