homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum


 3:18 pm on Nov 7, 2007 (gmt 0)

It has been suggested to me that I use 'Symlink' to enable me to access a folder on my server which is outside the www folder.

I need to access this folder: /homepages/40/d1******9/htdocs/photos/
from /homepages/40/d1******9/htdocs/pages/ I can't use the normal relative addressing in my php pages because although on the same server they are different domains.

I have come across the PHP Symlink function: [uk2.php.net...]

My question is do I put this code on every PHP page that needs to access the 'external' folder?

I'm on shared Linux hosting and cannot access the config files.



 4:47 pm on Nov 7, 2007 (gmt 0)

Yes you would need that code in all of the places that you want to use the link in.

You can include/require using a server path if that helps you i.e.
So you could set up whatever you want in the /photos/ directory then include it into you other pages. That still doesnt stop you having to put that code on every page though.


 5:51 pm on Nov 7, 2007 (gmt 0)

Thanks - I will give this a try. Hopefully it will be end to sleepless nights trying to solve this problem!

If I used - include('/homepages/40/d1******9/htdocs/photos/'); do I just refer to a file as if I'm already in that folder. For example, if I had an image callled mypic.jpg in the photos folder could I just refer to it as in <img src="mypic.jpg" >


 10:32 pm on Nov 7, 2007 (gmt 0)

No the include will only help you to get code across.
However you should be able to use some of the file functions.
Have you tried -
fopen [uk2.php.net] to get the contents of your picture?
If that doesnt work then have a look at curl [uk2.php.net], as you will be able to get it all with that.


 4:17 am on Nov 8, 2007 (gmt 0)

rsndll, the function symlink() creates a symbolic link to a file or directory. If you're not familiar with Linux/Unix, a symbolic link is kind of like a shortcut in Windows. Basically, you want to create a symbolic link called photos inside your blah/htdocs/pages/ folder to point to /homepages/40/d1******9/htdocs/photos/. You create the link once and it stays within your file system. After that, the URL pages.example.com/photos/mypic.jpg should resolve to the mypic.jpg file in your htdocs/photos folder.

There are many ways to create the symbolic link: If you have shell access, you can login, cd to the pages folder and create the symlobic link using the ln -s command. Or maybe your ftp program or cpanel file manager allows you to do that, or (what i usually do) just write a simple PHP script to call symlink() with the right arguments and run it once.

You may also need to enable the Apache Option "SymLinksIfOwnerMatch" or "FollowSymLinks" to your .htaccess file in the pages folder. (I'm guessing a bit here since i've never messed with symbolic links in the context of websites).

Hope this helps.


 5:27 pm on Nov 8, 2007 (gmt 0)

Thanks for all your help.

I have achieved what I wanted using a one-off PHP script as suggested.

Hopefully, this stays forever. I'm worried that if my web host does something to my server without me knowing (e.g. replace it) this link wil be lost.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved