Symlink breaking CodeIgniter upload library
My directory structure for my web app is in a dir like so:
within /home/staging:
proj
proj-builds
within /home/staging/proj:
uploads
www -> /home/staging/proj-builds/b-119/www
within /home/staging/proj-builds:
proj-b922
proj-b921
...
I made the www
a symlink to the latest b-#/www
directory of proj
, which i开发者_JAVA技巧s outside of the proj
dir.
When trying to upload something with the Upload class, I get this error: "The upload path does not appear to be valid"
This didn't happen when the dirs were not symlinked.
The Apache vhost is pointing to the www symlink.
Any idea on why this is happening and how to fix it?
Look at symlinks resolving ...
Since PHP 4.0.2 all symlinks are resolved which means that a script (ex.: myscript.php) you put in the /home/staging/proj/www/
folder will "see" itself not as /home/staging/proj/www/myscript.php
but rather as /home/staging/proj-builds/b-119/www/myscript.php
and that could cause some problems if the script expect to see itself at a pre-fixed location.
Please note that for PHP 5.2.x under Windows the symlinks are still not resolved, while for 5.3.x under Windows they are resolved. Under other Unix/Linux-like operating systems they are resolved in most cases.
You can use this ...
<?php print "__FILE__ = " . __FILE__ . "<br />\n"; ?>
... to see for yourself, putting it to a file at different locations.
The same principal applies for include/require statements.
So if the code that you're using expects to see a script, or have access to a folder, at fixed (may be defined in a config) location, ex.: /home/staging/proj/www/, it will not find it where expected.
The solution for that is to link the builds differently or to setup the config differently.
I can think of at least two possible solutions:
- You could have a simple permissions issue. Does Apache have full read access to that folder, and all parent folders?
- Your server could be configured to ignore symlinks. Make sure FollowSymLinks is enabled (and that you understand the risks involved).
Also, if you are dealing with uploads, PHP may be restricted or restricting you from saving the file outside the current directory, for example, Safe Mode.
精彩评论