New to PHP's file functions

    Date: 10/25/05 (PHP Community)    Keywords: php, html, web, apache

    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 = '';
    $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?

    Source: http://www.livejournal.com/community/php/357455.html

« Users online from several... || Arrays - removing... »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home