Image

Imagepatchwolf wrote in Imagephp

New to PHP's file functions

Hi all,

I'm trying to muddle through a site redesign of my website, and I've hit a stumbling block when it comes to the php file functions.

When I try to run the following script:



$string = '<?php echo \'foo\'; ?>';
$filename = 'test2.php';

// file_put_contents ($filename, $string); --- Doesn't work on my version of php.

fopen ($filename, 'w');
fwrite ($filename, $string);
fclose ($filename);



The following happens: the file test.php is created with no data and permissions set at 644. The directory has permissions of 777 for testing purposes. I also get the following errors displayed onscreen:

Warning: fwrite(): supplied argument is not a valid stream resource in /home/name/public_html/dev/test.php on line 21
Warning: fclose(): supplied argument is not a valid stream resource in /home/name/public_html/dev/test.php on line 22

What I want to happen is this: test2.php is created, with the string as the contents.

I'll build in some validators after I get this part working.

I'm using PHP Version 4.3.9, on Apache. It's a remote site, so I'm not sure that upgrading my version of php is a viable option.

Any ideas? Is there something I'm missing?