Creating a text file with PHP? -
i'm trying use php create text file, keep getting "can't open file" error. can tell me i'm doing wrong?
chmod('text.txt', 0777); $textfile = "text.txt"; $filehandle = fopen($textfile, 'w') or die("can't open file"); $stringdata = "hello!"; fwrite($filehandle, $stringdata); fclose($filehandle);
you're not going able chmod()
file doesn't exists. must have write privileges on parent folder in order allow apache
(if running apache, otherwise whichever user allowing write file) user write inside of folder (whether root, or sub folder).
additionally, should error handling on file writing:
<?php if($fh = fopen('text.txt','w')){ $stringdata = "hello!"; fwrite($fh, $stringdata,1024); fclose($fh); }
hope helps!
Comments
Post a Comment