+1  A: 

Make sure that your file is being uploaded before carrying any operation on it. Just dump the $_FILES array while development, like:

echo '<pre>'; print_r($_FILES);echo '</pre>';  

You need to have a enctype attribute applied on your <form> tag, for uploading a file. See http://www.w3.org/TR/html401/interact/forms.html#h-17.3

Sarfraz
I have added `enctype="multipart/form-data"`. The `[tmp_name] => C:\xampp\tmp\phpA3D5.tmp`, but I guess it's bad path? But still, if I don't add that if clause, then it uploads image perfectly. Omg :/
hey
Maybe because I use local I get this error?
hey
@hey: Yes, it could be difference in upload settings between your local server and online one.
Sarfraz
+1  A: 

First check if the upload is actually succeeding:

if ($_FILES['imagefile']['error'] === UPLOAD_ERR_OK) {
   if (!getimagesize(....)) {
      ... 
   }
} else {
   die("Upload failed with error code {$_FILES['imagefile']['error']}");
}

The error constants are defined here. Never assume an upload succeeded. There's only one way for them to work, and a million ways for them to fail.

Given that getimagesize() is complaining about an empty file name, either:

a. the upload failed, the reason code for which will be in the ...['error'] attribute.

b. you're checking the wrong file field name. If you've got <input type="file" name="image" /> then you have to check $_FILES['image'][...].

c. for whatever reason, your web server is able to WRITE files to the temporary directory, but does not have READ permissions.

Marc B