Cron Job Saving In Wrong Place

Status
Not open for further replies.

toptrump

New Member
Messages
4
Reaction score
0
Points
0
When I run my PHP script rugby_update it places the file in the same place as the script 'public_html' but when the cronjob does it, it places the finished .csv in the root.

Im not using any directories, Im just using the php with file put contents
 

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
Cron PHP jobs run in your 'root'

to put the file in folder [ public_html ] - your PHP script needs to use a absolute path (also known as relative-from-root)

Something like...
PHP:
<?php

$output = "My test file in public_html\n";

$hitsfile = fopen($_SERVER['DOCUMENT_ROOT'] . "/mytestfile.txt","ab");
fwrite($hitsfile , $output);
fclose($hitsfile);
?>
 
Status
Not open for further replies.
Top