Hi PHP community. I have a PHP script on Linux (CentOS 5.2) which produces a "failed to open stream: No such file or directory" which I am out of ideas on how to solve. I am on the verge of reverting to Perl.

The line generating the code is: $fh2 = fopen($fname,"rb") or die("can't open file"); When I replace $fname with actual file name it works. I have tried enclosing in single quotes, apostrophe, with path, without path, running as root and setting promiscuous permissions to no avail.

Here's actual output from the script and output of ls:

[hamid@grandma]$ php ./stripper.php
PHP Warning: fopen(/home/hamid/Outdoor2008-2_200A.csv
): failed to open stream: No such file or directory in /home/hamid/stripper.php on line 28

Warning: fopen(/home/hamid/Outdoor2008-2_200A.csv
): failed to open stream: No such file or directory in /home/hamid/stripper.php on line 28
[hamid@grandma]$
[hamid@grandma aurora]$ ls -l /home/hamid/Outdoor2008-2_200A.csv
-rwxrwxrwx 1 hamid apache 47264 Apr 11 19:18 /home/hamid/Outdoor2008-2_200A.csv

Any help will be greatly appreciated.

Thanks,
Hamid.

Thanks for your response, ShawnCplus. Variable fname indeed contains the correct file path:
fname=/home/hamid/Outdoor2008-2_200A.csv
and same result with mode set to "r".

Any other ideas or questions?

Thanks,
Hamid.

Thanks again, ShawnCplus. openbase_dir is set to /home/hamid in /etc/php.ini. PHP running version is 5.1.6, so over ride option in script is not available and no basedir in httpd.conf. I also tried setting to /home and "." all with the same result.

Don't let a good man (even if I do say so myself) revert to Perl. Lend your PHP expertise.

Thanks,
Hamid.

So if those errors you got are EXACTLY the errors you got then you need to trim() the $fname variable. It looks like it's ending in a carriage return.

I be hot damned, ShawnCplus! That was it! That invisible character at the end of string was making it fail. <admiration>I bow before your holiness.</admiration>

This question has already been answered. Start a new discussion instead.