SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    May 2002
    Location
    RI-USA
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Create new html file

    Is there a way to create and write to a new html file in php 4.1.2? I tried $file = fopen("filehere.html", "w"); but that doesn't work and mode x or x+ is only for 4.3. Any ideas on this?

  2. #2
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php.net (fopen) doesn't list any incompatibilities with previous versions and the fopen command. 'w' should work fine -- are you sure that PHP has write permissions to that directory?

    Are you getting any error messages?
    My name is Steve, and I'm a super-villian.

  3. #3
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by lieut_data
    php.net (fopen) doesn't list any incompatibilities with previous versions and the fopen command. 'w' should work fine -- are you sure that PHP has write permissions to that directory?

    Are you getting any error messages?
    Also note that if you don't use the full path to the file it will be created in the current working directory(cwd). At least that's how the cgi version works.

    --ed

  4. #4
    SitePoint Zealot
    Join Date
    May 2002
    Location
    RI-USA
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lieut_data
    php.net (fopen) doesn't list any incompatibilities with previous versions and the fopen command. 'w' should work fine -- are you sure that PHP has write permissions to that directory?

    Are you getting any error messages?
    I am getting one error message:

    Warning: Supplied argument is not a valid File-Handle resource in server/create.php on line 18



    and heres the code for it:

    PHP Code:
    <?php 
    $word
    ="Hi there";
    $filetitle=ereg_replace (" ""-"$word);
    $dir="http://www.mypage.com/_test/";
    $fileplace="$dir"$filetitle".html";
    $html ="
    <html>
    <head>
    <title>
    $word</title>
    </head>
    <body>
    Word: 
    $word
    </body>
    </html>"
    ;
    $file fopen("$fileplace""w");
    fwrite($html$file);
    fclose($file);
    ?>
    I set the folder to 777. The file doesn't exsist so I thought that was the error I was getting. But maybe php can't write to the dir, what would I check to make sure?

  5. #5
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by DigitalBurn
    $dir="http://www.mypage.com/_test/";
    $fileplace="$dir" . "$filetitle" . ".html";

    ?>[/PHP]
    Use the local path. Something like:
    $dir = '/home/username/www/path/to/dir/';

    And it may make your life easier to not have spaces in your file names.

    --ed

  6. #6
    SitePoint Zealot
    Join Date
    May 2002
    Location
    RI-USA
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by coo_t2
    Use the local path. Something like:
    $dir = '/home/username/www/path/to/dir/';

    And it may make your life easier to not have spaces in your file names.

    --ed
    Tried that, now I get a new error.

    Warning: fwrite(): supplied argument is not a valid stream resource

    Would this mean it does have access to write to the file? Thanks for your help.

  7. #7
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An invalid stream source suggests to me that it is the file pathname that is causing this error... as it is the pathname it's self that is the actual stream yes ?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •