Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 41

Thread: General Knowledge

  1. #31
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    File_put_contents:
    Code:
    <?php
    file_put_contents("file.html","<b>Hello</b>");
    ?>
    Jeremy | jfein.net

  2. #32
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I don't know about fopen() — that should work in PHP4 too. Check you haven't made some elementary error (path name? permissions?).

    file_put_contents() is only available in PHP5.

    A Small Orange has lots of features, but I hear that iWeb is very good, and offers better deals on space. Both provide PHP5. I'd be disinclined to go with iWeb for the sole reason that they need to be taught that the definition of an 'all-inclusive package' is that it, well, includes everything. Perhaps I'm overly picky.
    Last edited by Twey; 02-19-2009 at 01:53 AM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. The Following User Says Thank You to Twey For This Useful Post:

    bluewalrus (02-19-2009)

  4. #33
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Make sure that the folder is writable, and use the "x" or "x+" too!

    Aha, guess it is.
    Jeremy | jfein.net

  5. The Following User Says Thank You to Nile For This Useful Post:

    bluewalrus (02-19-2009)

  6. #34
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I'm going to have to assume I'm making some mistake then that's usually the case. Here is my code (I just rewrote this to double check and still no luck):

    PHP Code:
    <?php
    $create 
    fopen("newfile1asdfghjkl.txt""x");
    chmod($create0777) == true;
    $contents "This is text";
    fwrite($create$contents);
    fclose($create);
    ?>
    x error message:
    Warning: chmod() [function.chmod]: No such file or directory in /hsphere/local/home/crazychr/bluewalrus.net/thisthatthe.php on line 11
    x+ error message:
    Warning: fopen(newfile1asdfghjkl.txt) [function.fopen]: failed to open stream: File exists in /hsphere/local/home/crazychr/bluewalrus.net/thisthatthe.php on line 10

    Warning: chmod() [function.chmod]: No such file or directory in /hsphere/local/home/crazychr/bluewalrus.net/thisthatthe.php on line 11

    Warning: fwrite(): supplied argument is not a valid stream resource in /hsphere/local/home/crazychr/bluewalrus.net/thisthatthe.php on line 13

    Warning: fclose(): supplied argument is not a valid stream resource in /hsphere/local/home/crazychr/bluewalrus.net/thisthatthe.php on line 14
    The <?php is line 9 and ?>is line 15 Thanks for any more ideas you can offer here. I think I'll go with the orange server.

  7. #35
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    You can't change the mod of the file before its created!
    Jeremy | jfein.net

  8. #36
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Well, here's the obvious:
    Code:
    $create = fopen("newfile1asdfghjkl.txt", "x");
    chmod($create, 0777) == true;
    The fopen() fails because the file exists already — that's what 'x' (like 'x+') does. If you want to write to an existing file, use one of the 'a' (append) or 'w' (overwrite) family of flags.

    chmod() works with a filename, but you've given it a resource handle, so it's looking for a file named '5' or something (resource handles are long integers). What exactly is that == true supposed to do? It's redundant.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. The Following User Says Thank You to Twey For This Useful Post:

    bluewalrus (02-19-2009)

  10. #37
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    IT WORKED!!
    wahoo

    I don't know why it needs 2 = but it does. I tried it with 1 and that was the error then i put the second one and bamo I have a file created. Thanks.

    Working code...

    PHP Code:
    <?php
    $name 
    "newfile1asdfghjkl.txt";
    $create fopen($name"a");
    chmod($name0777) == true;
    $contents "This is text";
    fwrite($create$contents);
    fclose($create);
    ?>

  11. #38
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can remove it entirely. Just chmod($name, 0777); should suffice. All you're doing there is comparing the result to true and then discarding the result of the comparison.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  12. The Following User Says Thank You to Twey For This Useful Post:

    bluewalrus (02-24-2009)

  13. #39
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I have another one...

    How can I not have quotes auto escaped. This is what the code is being written as in my text files.
    Code:
    <object width=\"425\" height=\"344\"><param name=\"movie\" value=\"http://www.youtube.com/v/c7BS8adXyBE&hl=en&fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/c7BS8adXyBE&hl=en&fs=1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"425\" height=\"344\"></embed></object>
    That all comes from youtube but the =\" dont belong should just be =" or if not getting it to not write those how can i get it to ignore them when reading it with fread? Thanks for any ideas on this as well.

  14. #40
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Nothing to do with your file reading and writing. It sounds like magic_quotes_gpc. See http://www.php.net/magic_quotes.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •