 |
 |
PHP won't read a file in an Apache-accesible directory
|
 |
|
 |
|
Forum Regular
Join Date: Jun 2002
Location: New York
Status:
Offline
|
|
Hello,
I am trying to get a PHP script in my /Library/Webserver/Documents/ directory read the contents of a file in /Users/me/Public/, a directory that Apache has no trouble serving as I have made it accessible with the following addition to httpd.conf:
Alias /files "/Users/me/Public/"
<Directory "/Users/me/Public">
Options Indexes MultiViews
AllowOverride Limit
Order deny,allow
deny from all
ErrorDocument 403 /403.files.php
</Directory>
A .htaccess file in the folder allows access to the directory for authorized IP addresses.
I am very confident that the PHP code is correct. I only get ambiguous "File /some/path/to/file could not be opened" error messages.
I am thinking that Apache might not be letting PHP access the file. Is my httpd.conf in need of changes?
If you can't give a diagnosis based on this info, any sort of file permissions guidlines with Apache/PHP would be of great help in sorting out this mess.
For that matter, what else should I investigate?
Thanks,
Peter
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Oct 2000
Location: Vancouver
Status:
Offline
|
|
No, php should be able to read the file from anywere on your drive.. I do it all the time...
post the error, and the line of code where you try to read the file...
Are you using fopen() or include() or what???
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
Oh, the irony of having your signature unreadable by PHP
Perhaps it's just a simple permissions problem? Do a chown of 'nobody' on the files you want to access and they should be reachable.
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jun 2002
Location: New York
Status:
Offline
|
|
Originally posted by Alex Duffield:
No, php should be able to read the file from anywere on your drive.. I do it all the time...
post the error, and the line of code where you try to read the file...
Are you using fopen() or include() or what???
I am confident that there is a way. I love the limitless horizons of OS X and UNIX tools: the Classic ports of UNIX software were always so limiting. It's nice to know now that there's always a way to do what I want to do. But I digress...
Here is the error message:
Warning: fopen("/Users/peter/Public/Music/Erykah Badu/Baduizm/Next Lifetime.mp3 ", "rb") - No such file or directory in /Library/WebServer/Documents/lib/class.id3.php on line 215
This is a function in the class.id3.php file that I downloaded from http://leknor.com/code/. I modified it for clarity. It includes line 215:
function _read_v1() {
if (! ($f = fopen($this->file, 'rb')) ) {
$this->error = 'Unable to open ' . $file;
return false;
}
I had trouble with fopen() elsewhere. I had to use it in conjunction with fread()...
The permissions on the mp3 are 777 so it should be readable.
By the way, I use these snippets of code in a suite of pages I've made for my netradio station. Check out http://developer.apple.com/darwin/projects/streaming/ for a good time...
Thanks,
Peter
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jun 2002
Location: New York
Status:
Offline
|
|
Changing owner to nobody or to www:www (Apache user) doesn't help.
Peter
|
|
|
| |
|
|
|
 |
|
 |
|
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status:
Offline
|
|
Originally posted by SPiNdustrious:
Warning: fopen("/Users/peter/Public/Music/Erykah Badu/Baduizm/Next Lifetime.mp3 ", "rb") - No such file or directory
i'm seeing breaks in that filepath. could that be our problem here?
|
|
"Have sharp knives. Be creative. Cook to music" ~ maxelson
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jun 2002
Location: New York
Status:
Offline
|
|
The spaces/breaks are correct, but maybe fopen/PHP are choking on them.
Peter
|
|
|
| |
|
|
|
 |
|
 |
|
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status:
Offline
|
|
try this in Terminal:
cd /Users/peter/Public/Music/Erykah Badu/Baduizm
and you'll get:
No such file or directory
because it's looking for "/Users/peter/Public/Music/Erykah"
you have to type this, for any action:
cd /Users/peter/Public/Music/Erykah\ Badu/Baduizm
that space has to be escaped
so... what happens when you replace those spaces with underscores? does it work then, or are we playing with a new error message now?
|
|
"Have sharp knives. Be creative. Cook to music" ~ maxelson
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jun 2002
Location: New York
Status:
Offline
|
|
OK, after some playing around, I have determined that fopen() doesn't like the spaces in the filenames.
I tried escaping the spaces with a backslash but that didn't work.
Does anyone know how to get around this obstacle?
I'm not renaming the files...
Peter
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
Originally posted by SPiNdustrious:
OK, after some playing around, I have determined that fopen() doesn't like the spaces in the filenames.
I tried escaping the spaces with a backslash but that didn't work.
Does anyone know how to get around this obstacle?
I'm not renaming the files...
Peter
Can you add quotes to the filename?
E.g:
fopen('"/Users/peter/Public/Music/Erykah Badu/Baduizm"','rb');
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jun 2002
Location: New York
Status:
Offline
|
|
Hey hey hey! What bright boy you are Simon Mundy! It works!
Thank you all very much for the assistance.
Peter
|
|
|
| |
|
|
|
 |
|
 |
|
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status:
Offline
|
|
*sniff* i suss the spaces and Mundy gets all the glory...
damn you, Mundy! you blighter!
IM me sometime, foo' 
|
|
"Have sharp knives. Be creative. Cook to music" ~ maxelson
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
Originally posted by philzilla:
*sniff* i suss the spaces and Mundy gets all the glory...
damn you, Mundy! you blighter! 
IM me sometime, foo'
Race you to the next bug... 
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|