4

I have a html form that allows image uploads, but the image uploaded now fails the "is_uploaded_file" check for some reason.

So why does the upload fail the is_uploaded_file check?

HTML:

<form enctype="multipart/form-data" id="RecipeAddForm" method="post"
action="/recipes/add" accept-charset="utf-8">
    <!--- Omitted Markup -->
    <input type="file" name="data[Recipe][image]" value="" id="RecipeImage" />
    <!--- Omitted Markup -->
</form>

PHP:

// returns false
echo is_uploaded_file($file['tmp_name'])?'true':'false'; 

I did a dump on the $file or $_FILES array:

Array
(
    [name] => add or remove.jpg
    [type] => image/jpeg
    [tmp_name] => E:\\xampp\\tmp\\phpB9CB.tmp
    [error] => 0
    [size] => 71869
)

File size is not too large, and the error was 0. So why does it fail the is_uploaded_file check?

Razor Storm
  • 12,167
  • 20
  • 88
  • 148
  • 3
    Might be a problem with windows, since it's case sensitive and will not match if the path is different. Try using `realpath($file['tmp_name'])` – yoda Mar 05 '11 at 07:18
  • @yoda that worked! awesome thanks! Do you want to repost that as an answer so I can select it as correct? – Razor Storm Mar 05 '11 at 07:28

3 Answers3

6

Might be a problem with windows, since it's case sensitive and will not match if the path is different. Try using realpath($file['tmp_name'])

yoda
  • 10,834
  • 19
  • 64
  • 92
1

After you have used the uploaded image (move_uploaded_file) the function is_uploaded_file always returns false.

Darkhan ZD
  • 580
  • 8
  • 14
1

try with

if (is_uploaded_file($_FILES['data[Recipe][image]']['tmp_name']))

remember $_FILES is reserve PHP superglobal variable ..so always write in capital

u can retrieve the correct path of file using

$filename = basename($_FILES['userfile']['name']);

NOTE: why u using array in the name attribute ( name="data[Recipe][image]" ) ?

if there is no specific reason then alwayz make simple code

<input type="file" name="RecipeImage" value="" id="RecipeImage" />

and check simply

 if (is_uploaded_file($_FILES['RecipeImage']['tmp_name']))

Remember KISS

xkeshav
  • 53,360
  • 44
  • 177
  • 245