I am trying to create a file with PHP here is my code:
$file_to_send = 'ftp_test_from_created_file.txt';
chmod($file_to_send, 0777);
$fh = fopen($file_to_send,'w');
$tsv_line = 'Hey\tThese\tAre\tTab\tSeperated\tValues';
fwrite($fh, $tsv_line);
fwrite($fh, '\n');
$tsv_line = 'Hey\tThese\tAre\tToo';
fwrite($fh, $tsv_line);
fclose($fh);
This clearly gives me an error because I am trying to set permissions on a file that does not exist yet. Although if I skip the chmod call I get an another error telling me I do not have permissions set. So either I am in a sick chicken vs egg cycle or I need to set the permissions on the containing directory...but how? it tried all of the folling:
chmod('../containingfolder/', 0777);
chmod('../', 0777);
chmod('', 0777);
None of which work... what should I do? Oh and by the way once I am done do I need to change the permissions back?
Thanks!
UPDATE I tried chmod('.', 0777) and this is the error I got:
Warning: chmod(): Operation not permitted
The only reason I am trying to make this file is so I can FTP it somewhere else, then I planned to unlink() it. So if there is a better way? Like maybe storing the file in memory to send it(don't know if thats possible)? Also I am using PHP4. Thanks!