0

I want to move my data directory outside of the web root. I have file paths stored in my database and would like to be able to redirect looking for files through a symlink instead of having to change the saved paths.

Example, currently I have a structure like this:

/root/webroot/data/file.ext

And my database path will be: /root/webroot/data/file.ext as well. I'd like to move data outside of webroot so I have:

/root/data/file.ext
/root/webroot/data -> root/data

Where /root/webroot/data is a linux style symlink to root/data. I have set this up, but when I do a readfile on the previously stored path (/root/webroot/data/file.ext) it fails. I.e. I do this:

readfile('/root/webroot/data/file.ext');

I get back:

Warning:  readfile(/root/webroot/data/file.ext) [function.readfile]: failed to open stream: No such file or directory in [file] on line ...

Is there anything I can do to help these paths resolve?

Note: The permissions of the folders and files all match. That of the symlink is root:root, from which it was created, but chown doesn't seem to work on it.

garromark
  • 814
  • 8
  • 20
  • Stupid question, but is your symlink correct? I.e. can you traverse it on the cli? From what you wrote above it looks like it would be looking for the dir in root/webroot/root/data. – Noodles Feb 15 '12 at 04:25
  • 1
    Wouldn't it be easier to update the database? – John V. Feb 15 '12 at 04:27
  • Noodles, the problem was indeed with the symbolic link. It had a "relative" redirection without a leading slash that confused it. Changed it to the entire absolute path and it fixed it. – garromark Feb 15 '12 at 06:15

1 Answers1

0

Where are you running the script from? If you are calling the directory without the leading slash:

readfile('root/webroot/data/file.ext');

then you better make sure it is running in the same directory root is sitting in. However, if you are running this from webroot, you will need to update the readfile path to something like:

readfile('data/file.ext');
Chuck Burgess
  • 11,600
  • 5
  • 41
  • 74
  • Hey, the leading slash actually exists in the problem... "root" was just supposed to mean /home/[name of site]. I updated problem. – garromark Feb 15 '12 at 06:10