Forum Moderators: coopster

Message Too Old, No Replies

Accessing Document from outside Document Root

         

max4

10:46 pm on Jun 19, 2010 (gmt 0)

10+ Year Member



Hi,

We plan on running a crontab on our LAMP server to access a php script that is outside of the www (htdocs) folder. This script basically finds and removes expired records from our database. We would like this script to be situated outside of the root directory so that it is not accessible by the general public. The problem is that this script needs access to files within the root, and we are not sure about how to format the file path to target these files.

Here is where the problem occurs:


$original_file = "./img/uploads/thumbs/tm_{$original_image}";
$open = fopen($original_file, 'w') or die("Unexpected error");


fopen throws an unexpected error because the file is inaccessible from the directory we are running the script. How can we overcome this obstacle?

Thank you.

dreamcatcher

7:06 am on Jun 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi max4,

Always use the full server path.

$original_file = "/home/username/server/public_html/img/uploads/thumbs/tm_{$original_image}";
$open = fopen($original_file, 'w') or die("Unexpected error");

Paths vary from server to server, but you get the idea.

dc

rocknbil

4:39 pm on Jun 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, there's that (and is important when doing this kind of stuff,) but the OP is *outside* of public_html (i.e., htdocs.)

It's very likely your script won't have permissions to do this. Most of the time these systems have a _private directory which serves this purpose, have you got one?

max4

6:01 pm on Jun 27, 2010 (gmt 0)

10+ Year Member



Hi dreamcatcher, rocknbil,

We were unable to get crontab to access that script because php was compiled with apache and therefore we had to use the lynx browser with cron to access the file. The consequence of this is that the file has to be situated in the document root though a few scriptual additions have made access to that file fruitless (outside of server access, which has a function). Because the script has to be situated in the root directory, defining a file path is no longer an issue; though if it still were I'm sure your solutions would correct any unusual behavior.

Thank you for your suggestions