thewooleymammoth Posted September 16, 2007 Share Posted September 16, 2007 How do i write files to a directory? i can only figure out how to make the site open files in the same directory as as the script file, is there osme way to tell it to read or write a directory? say in /files/? Link to comment https://forums.phpfreaks.com/topic/69586-solved-writing-files-to-a-directory/ Share on other sites More sharing options...
rarebit Posted September 16, 2007 Share Posted September 16, 2007 If your in 'www.there.com/mydir/', then to go up a dir would be '../file.html', or to go into a dir called 'other' use 'other/file.html'. Link to comment https://forums.phpfreaks.com/topic/69586-solved-writing-files-to-a-directory/#findComment-349689 Share on other sites More sharing options...
thewooleymammoth Posted September 16, 2007 Author Share Posted September 16, 2007 so this should place a file called 1.txt inside www.mysite.com/files/1.txt ? <?php $result=1; $filename=files/$result.".txt"; $openfile = fopen($filename, "a") or die("could not open file $filename"); fwrite($openfile, 'this is the text'); ?> that doesnt work, it tries to devide files by 1 which is undefined so the file ends in the same directory called 0.txt Link to comment https://forums.phpfreaks.com/topic/69586-solved-writing-files-to-a-directory/#findComment-349695 Share on other sites More sharing options...
rarebit Posted September 16, 2007 Share Posted September 16, 2007 $filename=files/$result.".txt" should be $filename="files/".$result.".txt" Link to comment https://forums.phpfreaks.com/topic/69586-solved-writing-files-to-a-directory/#findComment-349700 Share on other sites More sharing options...
thewooleymammoth Posted September 16, 2007 Author Share Posted September 16, 2007 ah thanks Link to comment https://forums.phpfreaks.com/topic/69586-solved-writing-files-to-a-directory/#findComment-349701 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.