Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: How to overwrite?

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to overwrite?

    I am making a script and i came upon a need to overwrite a file rather than just add to it. I am using $file = @fopen($filename, "w"); but that just adds. Does anyone know the code to overwrite? Thanks for the help

  2. #2
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    http://us3.php.net/fopen
    PHP Code:
    $file = @fopen($filename"w+"); 

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by blm126
    http://us3.php.net/fopen
    PHP Code:
    $file = @fopen($filename"w+"); 
    I actually tried that before and it didn't work. I also just tried it again and still no good . By what it says on that page, a simple "w" should work too, but it doesn't. Anyone know whats wrong?

  4. #4
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Your right, "w" should be enough. But "that page" is the PHP manual, and I'm pretty sure it is right sooooo. Make sure
    • Safe mode is not enabled(or that the PHP user is the owner of the file)
    • $filename is NOT a URL eg. http://www.blah.com
    • fopen() is not failing. Remove the "@' in front of fopen to find out

  5. #5
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by blm126
    Your right, "w" should be enough. But "that page" is the PHP manual, and I'm pretty sure it is right sooooo. Make sure
    • Safe mode is not enabled(or that the PHP user is the owner of the file)
    • $filename is NOT a URL eg. http://www.blah.com
    • fopen() is not failing. Remove the "@' in front of fopen to find out
    Ok, i made sure of the second 2 things you said and they check out, but I have cpanel and I am not sure how to check safe mode. Do I just talk to my host? thanks

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You could make a php page with

    PHP Code:
    <? 

    phpinfo
    (); 

    ?>
    and it will say if Safe Mode is enabled. If so, being that you use CPanel, I doubt that your webhost will disable it, but every webhost is different.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by Titan85
    Do I just talk to my host? thanks
    Always a good way to find things out, but phpinfo() will tell you. If you could post your complete code I might be able to find the problem

  8. #8
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok, i ran the phpinfo() script and didn't see anything saying safe mode was enabled. Here is the php info http://echodesign.jexhost.com/testing/test.php

  9. #9
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    It is disabled. I am going to see more code to find the problem

  10. #10
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by blm126
    It is disabled. I am going to see more code to find the problem
    Do you mean you need some of the script code? Also, could the file to write to being a .txt be a problem?

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
  •