The Little Guy Posted September 18, 2007 Share Posted September 18, 2007 Why isn't this writing to the file? <?php $vals = '../includes/values.php'; fopen($vals,"w"); $write = 'this is what will be in the file.'; if (is_writable($vals)) { if(fwrite($vals, $write)){ echo 'Saved!'; }else{ echo 'Not Saved!'; } }else{ echo 'Can\'t write to file'; } ?> Warning: fwrite(): supplied argument is not a valid stream resource in /home/.marble/ryannaddy/iconnect.publicsize.com/vamp/testScripts/ShopingCart/process/install.php on line 76 if(fwrite($vals, $write)){ Quote Link to comment https://forums.phpfreaks.com/topic/69748-solved-fwrite/ Share on other sites More sharing options...
AV1611 Posted September 18, 2007 Share Posted September 18, 2007 you have to chmod the file to allow write access to it I think... Quote Link to comment https://forums.phpfreaks.com/topic/69748-solved-fwrite/#findComment-350433 Share on other sites More sharing options...
xyn Posted September 18, 2007 Share Posted September 18, 2007 I would declare $vals to the actual directory. $_SERVER['DOCUMENT_ROOT'] = /home/user/www $_SERVER['DOCUMENT_ROOT']."/includes/file.txt"; Quote Link to comment https://forums.phpfreaks.com/topic/69748-solved-fwrite/#findComment-350436 Share on other sites More sharing options...
Jessica Posted September 18, 2007 Share Posted September 18, 2007 also, not how you use fopen. You need to assign the resource it creates to a variable in order to use it. Quote Link to comment https://forums.phpfreaks.com/topic/69748-solved-fwrite/#findComment-350439 Share on other sites More sharing options...
xyn Posted September 18, 2007 Share Posted September 18, 2007 Example for what jesirose says; $h = fopen($file, "w"); if(fwrite($h, $text)) { echo('wrote'); } else{ die('not wrote'); } Quote Link to comment https://forums.phpfreaks.com/topic/69748-solved-fwrite/#findComment-350445 Share on other sites More sharing options...
The Little Guy Posted September 18, 2007 Author Share Posted September 18, 2007 also, not how you use fopen. You need to assign the resource it creates to a variable in order to use it. That was the exact problem, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/69748-solved-fwrite/#findComment-350507 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.