Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP won't read a file in an Apache-accesible directory

PHP won't read a file in an Apache-accesible directory
Thread Tools
Forum Regular
Join Date: Jun 2002
Location: New York
Status: Offline
Reply With Quote
Nov 22, 2002, 03:18 PM
 
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
Reply With Quote
Nov 22, 2002, 03:25 PM
 
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???
Alex Duffield
http://www.incontrolsolutions.com
Fatal error: Call to undefined function: signature() in /usr/local/www/htdocs/showthread.php on line 813
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Nov 22, 2002, 04:15 PM
 
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
Reply With Quote
Nov 22, 2002, 04:33 PM
 
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
Reply With Quote
Nov 22, 2002, 04:38 PM
 
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
Reply With Quote
Nov 22, 2002, 05:33 PM
 
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
Reply With Quote
Nov 22, 2002, 05:54 PM
 
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
Reply With Quote
Nov 22, 2002, 06:59 PM
 
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
Reply With Quote
Nov 23, 2002, 02:44 PM
 
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
Reply With Quote
Nov 23, 2002, 04:13 PM
 
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
Reply With Quote
Nov 23, 2002, 05:34 PM
 
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
Reply With Quote
Nov 23, 2002, 07:36 PM
 
*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
Reply With Quote
Nov 24, 2002, 02:45 PM
 
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...
     
   
Thread Tools
Forum Links
Forum 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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:23 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2