PHP function (file_exists) with mapped drive

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
twright
Forum Newbie
Posts: 4
Joined: Tue Jun 10, 2008 5:33 pm

PHP function (file_exists) with mapped drive

Post by twright »

I have been trying unsuccesfully to use php functions like file_exists with a folder that has been defined through apache alias. I can do a localhost/folder and see the contents of the folder, but I have not been able to make php see the folder. I must be missing something here. Any help?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP function (file_exists) with mapped drive

Post by Benjamin »

Have you checked that ALL parts of the path are readable by apache?

ie

/path/path2/path3/file

All 3 folders must have execute (traverse) permission for apache and the file must have read permission for apache.
twright
Forum Newbie
Posts: 4
Joined: Tue Jun 10, 2008 5:33 pm

Re: PHP function (file_exists) with mapped drive

Post by twright »

Guess I am embarassed to say, I am not sure I know how to test that. I also failed to mention that this is being done in a windows environment.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP function (file_exists) with mapped drive

Post by Eran »

Are you trying to use file_exists() on a relative path or an absolute one? When in doubt, always use absolute
twright
Forum Newbie
Posts: 4
Joined: Tue Jun 10, 2008 5:33 pm

Re: PHP function (file_exists) with mapped drive

Post by twright »

I am using the following alias:

Alias /rofile/ "d:/rof/"

<Directory "d:/rof">
Options FollowSymLinks Indexes Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Then I am trying access a file as follows and create a link to the file:

$fp="rofile/1001.pdf";
if (file_exists($fp)) echo "<a href='".$fp."' target='new'>";

I have tried various combinations of slashes and no slashes.
I have also removed the if condition so the link appeared, when clicked, I get a 404 error. However when I go to 'localhost/rofile/', i see the files that are stored in the folder.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP function (file_exists) with mapped drive

Post by Benjamin »

file_exists will require the file system path, not the url. ie d:/rof/filename.pdf

http://us2.php.net/manual/en/function.file-exists.php
twright
Forum Newbie
Posts: 4
Joined: Tue Jun 10, 2008 5:33 pm

Re: PHP function (file_exists) with mapped drive

Post by twright »

Alright then, problem solved! Thanks so much.. this is fabulous.

End result:

alias info as above

$fp="1001.pdf";
if (file_exists('d:/rof/'.$fp)) echo "<a href='http://ipaddy/rofile/".$fp."' target='new'>";

Again, thank you!
Post Reply