is_file() returns false for uploaded files?

This is a discussion on is_file() returns false for uploaded files? within the PHP Language forums, part of the PHP Programming Forums category; Running IIS 6 on Windows 2003 server. After an update to the most recent version of php 5.1.2, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2006
Kimmo Laine
 
Posts: n/a
Default is_file() returns false for uploaded files?

Running IIS 6 on Windows 2003 server.

After an update to the most recent version of php 5.1.2, for some reacon
a function handling uploaded files using is_file stopped working. is_file
failed for existing files. I fixed it by changing is_file to
file_exists, then it worked again. Prior to the update, in the older
version, presumably it was 5.0.1, is_file worked just fine without
problems.

<?php
echo 'is_file:' . (is_file($_FILES['myfile']['tmp_name']) ? 'true' :
'false');
echo 'file_exists:' . (file_exists($_FILES['myfile']['tmp_name']) ? 'true' :
'false');
?>

<form action="<?php echo $_SERVER['PHP_SELF'] ?>"
enctype="multipart/form-data" method="post">
<input type="file" name="myfile" />
<input type="submit" />
</form>

Submitted a bug report already http://bugs.php.net/bug.php?id=37118 but if
someone has any ideas what's going on here please reply.

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)


Reply With Quote
  #2 (permalink)  
Old 04-18-2006
Andy Jeffries
 
Posts: n/a
Default Re: is_file() returns false for uploaded files?

On Tue, 18 Apr 2006 12:54:08 +0300, Kimmo Laine wrote:
> Running IIS 6 on Windows 2003 server.
>
> After an update to the most recent version of php 5.1.2, for some reacon a
> function handling uploaded files using is_file stopped working. is_file
> failed for existing files. I fixed it by changing is_file to file_exists,
> then it worked again. Prior to the update, in the older version,
> presumably it was 5.0.1, is_file worked just fine without problems.
>
> <?php
> echo 'is_file:' . (is_file($_FILES['myfile']['tmp_name']) ? 'true' :
> 'false');
> echo 'file_exists:' . (file_exists($_FILES['myfile']['tmp_name']) ? 'true'
> : 'false');
> ?>


For this use, shouldn't you be using is_uploaded_file anyway?

Cheers,


Andy


--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Reply With Quote
  #3 (permalink)  
Old 04-18-2006
Kimmo Laine
 
Posts: n/a
Default Re: is_file() returns false for uploaded files?

"Andy Jeffries" <news@andyjeffries.co.uk> wrote in message
news:pan.2006.04.18.11.54.20.716987@andyjeffries.c o.uk...
> On Tue, 18 Apr 2006 12:54:08 +0300, Kimmo Laine wrote:
>> Running IIS 6 on Windows 2003 server.
>>
>> After an update to the most recent version of php 5.1.2, for some reacon
>> a
>> function handling uploaded files using is_file stopped working. is_file
>> failed for existing files. I fixed it by changing is_file to file_exists,
>> then it worked again. Prior to the update, in the older version,
>> presumably it was 5.0.1, is_file worked just fine without problems.
>>
>> <?php
>> echo 'is_file:' . (is_file($_FILES['myfile']['tmp_name']) ? 'true' :
>> 'false');
>> echo 'file_exists:' . (file_exists($_FILES['myfile']['tmp_name']) ?
>> 'true'
>> : 'false');
>> ?>

>
> For this use, shouldn't you be using is_uploaded_file anyway?
>


Possibly so, but that does not remove the bug. It's a piece of code I've
done some years ago that has worked fine even though a it's not perfect.
Still I'd like to be able to get similar results with is_file and
file_exists regardless of the file being user upload or not.

If this is not a bug but a feature, I'd like to see it explained in the
manual just what it means. ATM, it says in the manual: "is_file -- Tells
whether the filename is a regular file". So, what IS a regular file? What's
the difference between file_exists and is_file because they return different
results. I don't get it. And what bothers me the most is that up to this
point is_file has returned true. Why change it?

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)


Reply With Quote
  #4 (permalink)  
Old 04-18-2006
milahu
 
Posts: n/a
Default Re: is_file() returns false for uploaded files?

The uploaded file is stored in a temporary folder outside your usual
PHP `filesystem'.
IIS seems to deny direct access to this folder, so you have to stick to
PHP's special functions for handling file uploads.

is_file() checks for regular files and returns false on directories or
symlinks, while file_exists() returns true, if the file, link or
directory exists.

Reply With Quote
  #5 (permalink)  
Old 04-19-2006
Kimmo Laine
 
Posts: n/a
Default Re: is_file() returns false for uploaded files?

"milahu" <milahu@googlemail.com> wrote in message
news:1145365711.177670.64360@u72g2000cwu.googlegro ups.com...
> The uploaded file is stored in a temporary folder outside your usual
> PHP `filesystem'.
> IIS seems to deny direct access to this folder, so you have to stick to
> PHP's special functions for handling file uploads.
>


So now copy() is a special function? I use just copy to handle uploaded
files, in that particular script. I could fix it to use move_uploaded_files
but it works now. "If it works don't fix it." And IIS does not deny access
to it as I can access it with copy. I don't have to use
move_uploaded_files() if that is what you mean by special function.

> is_file() checks for regular files and returns false on directories or
> symlinks, while file_exists() returns true, if the file, link or
> directory exists.


But an uploaded file is neither a symlink (windows filesystem has no
symlinks) nor a directory, it's just a normal file. Now what exactly is the
determination of a "regular file", if the uploaded file is not one?

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)


Reply With Quote
  #6 (permalink)  
Old 04-20-2006
milahu
 
Posts: n/a
Default Re: is_file() returns false for uploaded files?

> So now copy() is a special function?
Yes, it's holy for usual files, but not for uploaded ones. Why do you
just dislike move_uploaded_file() that much? PHP is not always as
logical as one would like it to be...

> But an uploaded file is neither a symlink [...]

Already tested with is_link()? Win / NTFS doesn't support symlinks, so
I guess Apache emulates 'em.

Reply With Quote
  #7 (permalink)  
Old 04-20-2006
Kimmo Laine
 
Posts: n/a
Default Re: is_file() returns false for uploaded files?

"milahu" <milahu@googlemail.com> wrote in message
news:1145531261.880053.317800@i40g2000cwc.googlegr oups.com...
>> So now copy() is a special function?

> Yes, it's holy for usual files, but not for uploaded ones. Why do you
> just dislike move_uploaded_file() that much? PHP is not always as
> logical as one would like it to be...


Nothing. move_uploaded_files and copy are not the issue here, both work just
fine. The problem is that is_file does not recognize an uploaded file as a
file, while file_exists does and I'd like to know why.

>> But an uploaded file is neither a symlink [...]

> Already tested with is_link()? Win / NTFS doesn't support symlinks, so
> I guess Apache emulates 'em.


Nothing to do with Apache either, using IIS 6 as I already said in my first
post.

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:58 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0