[PHP] file_exists, Windows, and EasyPHP
I've written a plugin for DokuWiki which uses the following DokuWiki function for reading files: function io_readFile($file,$clean=true){ $ret = ''; if(@file_exists($file)){ if(substr($file,-3) == '.gz'){ $ret = join('',gzfile($file)); }else if(substr($file,-4) == '.bz2'){ $ret = bzfile($file); }else{ $ret = join('',file($file)); } } if($clean){ return cleanText($ret); }else{ return $ret; } } On Linux machines, this seems to behave as you would hope, that is, if the file doesn't exist then you get back a null string. In any event, none of the users who have installed it on Linux machines have had a problem with it. And I have done several installs myself. But one user installed the plugin on a Windows machine and the code fell through to $ret = join('',file($file)) even though there was no $file. The result was an error message: Permission denied in *E:\Program Files\EasyPHP 2.0b1\www\dokuwiki\inc\io.php* on line *97 *Line 97 is the join. So the function is attempting to read a non-existent file. I was just wondering whether there is some difference in the way his PHP version handles the @ operator in: if(@file_exists($file)) That is, is it possible that by suppressing errors, this expression somehow returns true? And is it a bug? Thanks. Myron -- _ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_exists, Windows, and EasyPHP
On Jun 18, 2007, at 3:30 PM, Myron Turner wrote: I've written a plugin for DokuWiki which uses the following DokuWiki function for reading files: function io_readFile($file,$clean=true){ $ret = ''; if(@file_exists($file)){ if(substr($file,-3) == '.gz'){ $ret = join('',gzfile($file)); }else if(substr($file,-4) == '.bz2'){ $ret = bzfile($file); }else{ $ret = join('',file($file)); } } if($clean){ return cleanText($ret); }else{ return $ret; } } On Linux machines, this seems to behave as you would hope, that is, if the file doesn't exist then you get back a null string. In any event, none of the users who have installed it on Linux machines have had a problem with it. And I have done several installs myself. But one user installed the plugin on a Windows machine and the code fell through to $ret = join('',file($file)) even though there was no $file. The result was an error message: Permission denied in *E:\Program Files\EasyPHP 2.0b1 \www\dokuwiki\inc\io.php* on line *97 *Line 97 is the join. So the function is attempting to read a non- existent file. I was just wondering whether there is some difference in the way his PHP version handles the @ operator in: if(@file_exists($file)) That is, is it possible that by suppressing errors, this expression somehow returns true? And is it a bug? Are you sure the file doesn't exist? Could it just be that it exists, but the permissions are not set correctly? Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_exists, Windows, and EasyPHP
Edward Vermillion wrote: On Jun 18, 2007, at 3:30 PM, Myron Turner wrote: I've written a plugin for DokuWiki which uses the following DokuWiki function for reading files: function io_readFile($file,$clean=true){ $ret = ''; if(@file_exists($file)){ if(substr($file,-3) == '.gz'){ $ret = join('',gzfile($file)); }else if(substr($file,-4) == '.bz2'){ $ret = bzfile($file); }else{ $ret = join('',file($file)); } } if($clean){ return cleanText($ret); }else{ return $ret; } } On Linux machines, this seems to behave as you would hope, that is, if the file doesn't exist then you get back a null string. In any event, none of the users who have installed it on Linux machines have had a problem with it. And I have done several installs myself. But one user installed the plugin on a Windows machine and the code fell through to $ret = join('',file($file)) even though there was no $file. The result was an error message: Permission denied in *E:\Program Files\EasyPHP 2.0b1\www\dokuwiki\inc\io.php* on line *97 *Line 97 is the join. So the function is attempting to read a non-existent file. I was just wondering whether there is some difference in the way his PHP version handles the @ operator in: if(@file_exists($file)) That is, is it possible that by suppressing errors, this expression somehow returns true? And is it a bug? Are you sure the file doesn't exist? Could it just be that it exists, but the permissions are not set correctly? Ed I don't really know, since I am depending on the user's feed-back. But apparently he hadn't done anything yet with the plugin, so no files would have been in that directory. But it's a possibility since the code doesn't check for whether the file is readable. It could just be a Windows issue, but I thought I'd check here, because if it's something that others have run into and which I can rectify I'd want to do it. -- _ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_exists, Windows, and EasyPHP
Myron Turner wrote: I've written a plugin for DokuWiki which uses the following DokuWiki function for reading files: function io_readFile($file,$clean=true){ $ret = ''; if(@file_exists($file)){ if(substr($file,-3) == '.gz'){ $ret = join('',gzfile($file)); }else if(substr($file,-4) == '.bz2'){ $ret = bzfile($file); }else{ $ret = join('',file($file)); } } if($clean){ return cleanText($ret); }else{ return $ret; } } On Linux machines, this seems to behave as you would hope, that is, if the file doesn't exist then you get back a null string. In any event, none of the users who have installed it on Linux machines have had a problem with it. And I have done several installs myself. But one user installed the plugin on a Windows machine and the code fell through to $ret = join('',file($file)) even though there was no $file. The result was an error message: Permission denied in *E:\Program Files\EasyPHP 2.0b1\www\dokuwiki\inc\io.php* on line *97 *Line 97 is the join. So the function is attempting to read a non-existent file. I was just wondering whether there is some difference in the way his PHP version handles the @ operator in: if(@file_exists($file)) That is, is it possible that by suppressing errors, this expression somehow returns true? And is it a bug? Thanks. Myron First off, don't jack someone else's thread. Secondly, I think it might have something to do with the space in the file name. Try changing all spaces to %20 and see what happens. $string = str_replace(' ', '%20', $string); should do the trick -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_exists, Windows, and EasyPHP
On 6/18/07, Jim Lucas [EMAIL PROTECTED] wrote: First off, don't jack someone else's thread. Am I not getting all of the list messages today? I didn't see where the thread hijacking occurred -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_exists, Windows, and EasyPHP
Jim Lucas wrote: First off, don't jack someone else's thread. Secondly, I think it might have something to do with the space in the file name. Try changing all spaces to %20 and see what happens. $string = str_replace(' ', '%20', $string); should do the trick -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare Since my own reader isn't threaded I wasn't aware of the threading issue. I'll keep this in mind in the future. I assume by spaces you are referring to E:\Program Files\. Well, if a php package for windows can't understand its own file system something is seriously wrong. But in fact that's not the case since dokuwiki runs on the system and uses io_readFile. Glad to see you are now crediting Shakespeare. -- _ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_exists, Windows, and EasyPHP
Daniel Brown wrote: On 6/18/07, Jim Lucas [EMAIL PROTECTED] wrote: First off, don't jack someone else's thread. Am I not getting all of the list messages today? I didn't see where the thread hijacking occurred -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_exists, Windows, and EasyPHP
On 6/18/07, Jim Lucas [EMAIL PROTECTED] wrote: Daniel Brown wrote: On 6/18/07, Jim Lucas [EMAIL PROTECTED] wrote: First off, don't jack someone else's thread. Am I not getting all of the list messages today? I didn't see where the thread hijacking occurred -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare Weird, I didn't get those messages. I wasn't being a smartass, I was legitimately wondering if I was missing emails from the list today, and apparently I am. Thanks, Jim. -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php