Jump to content

[SOLVED] Not a valid stream resource...


brooklyn_guy

Recommended Posts

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);

Link to comment
https://forums.phpfreaks.com/topic/83814-solved-not-a-valid-stream-resource/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.