brooklyn_guy Posted December 31, 2007 Share Posted December 31, 2007 Hi all, I am writing a simple test code that creates a directory and then fopens and writes to a file...but I have no idea why I am getting an error. As you can see in the code below, permissions are checked and set correctly to 0777...so, what gives? I have had a difficult time finding the answer online, so any help would be much appreciated. Could be a problem with php.ini? My Host's server settings? And what is a valid stream resource anyways? Thanks a lot, here is the code: mkdir("/home/folder/public_html/test_dir", 0777); $dir_perms_1 = substr(sprintf('%o', fileperms('/home/folder/public_html/test_dir')), -4); echo $dir_perms_1 . '= dir perms<br>'; $did_work_2 = chmod('/home/folder/public_html/test_dir', 0777); echo $did_work_2 . '= did it work?<br>'; $dir_perms_2 = substr(sprintf('%o', fileperms('/home/folder/public_html/test_dir')), -4); echo $dir_perms_2 . '= dir perms<br>'; $new_file = "/home/folder/public_html/test_dir/test_file.php"; fopen($new_file, 'w') or die("can't open file"); $file_perms_1 = substr(sprintf('%o', fileperms($new_file)), -4); echo $file_perms_1 . '= file perms 1<br>'; $did_work_2 = chmod($new_file, 0777); echo $did_work_2 . '= did it work?<br>'; $file_perms_2 = substr(sprintf('%o', fileperms($new_file)), -4); echo $file_perms_2 . '= file perms 2<br>'; $stringData = "Hello\n"; fwrite($new_file, $stringData); $stringData = "World\n"; fwrite($new_file, $stringData); fclose($new_file); Quote Link to comment https://forums.phpfreaks.com/topic/83814-solved-not-a-valid-stream-resource/ Share on other sites More sharing options...
rajivgonsalves Posted December 31, 2007 Share Posted December 31, 2007 this fopen($new_file, 'w') or die("can't open file"); should be $new_file = fopen($new_file, 'w') or die("can't open file"); Quote Link to comment https://forums.phpfreaks.com/topic/83814-solved-not-a-valid-stream-resource/#findComment-426463 Share on other sites More sharing options...
brooklyn_guy Posted December 31, 2007 Author Share Posted December 31, 2007 Perfect, thanks! How simple. And I take your comment about commenting code to heart. Quote Link to comment https://forums.phpfreaks.com/topic/83814-solved-not-a-valid-stream-resource/#findComment-426734 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.