Results 1 to 9 of 9

Thread: fread/fwrite help

  1. #1

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    fread/fwrite help

    Okay. How would i go about in doing this.

    Open file -> delete contents -> add new content -> display content

    so far ive only been able to read and write.but not delete the contents.
    Last edited by PlaGuE; Nov 10th, 2005 at 04:52 AM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: fread/fwrite help

    You can open the file in truncated write mode. Whereby the file contents is wiped when you open it.
    PHP Code:
    $f fopen('file/path''wb'); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: fread/fwrite help

    thanks...
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  4. #4

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: fread/fwrite help

    Another question that goes along this line.

    how would i go about in.... creating a file that doesnt exist. when the page loads...

    heres my code.
    all files are put to 0777
    PHP Code:
    <?php

    $filename 
    "empty_page.php";
    $somecontent "test\r\n";

    // Let's make sure the file exists and is writable first.
    if (is_writable($filename)) {

       if (!
    $handle fopen($filename'wb')) {
             echo 
    "Cannot open file ($filename)";
             exit;
       }

       
    // Write $somecontent to our opened file.
       
    if (fwrite($handle$somecontent) === FALSE) {
           echo 
    "Cannot write to file ($filename)";
           exit;
       }
       echo 
    "Success, wrote ($somecontent) to file ($filename)";
      
       
    fclose($handle);

    } else {
       echo 
    "The file $filename is not writable";
    }
    ?>
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: fread/fwrite help

    If the file doesn't exists, fopen will always try to create it.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: fread/fwrite help

    pfft...

    now it works...

    lol... i left it alone for 15 mins ... and come back to it... and it works... OoOo Scary. o.O
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  7. #7

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: fread/fwrite help

    okay another Question...

    NO STEALY IDEA.

    PHP Code:
    if($_GET['page'] == ""){
    $sql="Select * from pages WHERE name = 'home'";
    $result mysql_query($sql);

    while(
    $row mysql_fetch_array($result)):
    ///////////////////////////////////////////////////////

    $filename $_GET['page'] . ".php";
    $somecontent "$row[content]";

    // Let's make sure the file exists and is writable first.
       
    if (!$handle fopen($filename'wb')) {
             echo 
    "Cannot open file ($filename)";
             exit;
       }

       
    // Write $somecontent to our opened file.
       
    if (fwrite($handle$somecontent) === FALSE) {
           echo 
    "Cannot write to file ($filename)";
           exit;
       }
      
           
    fclose($handle);
           
    chmod("$filename"0777);
    ///////////////////////////////////////////////////////
    include("$filename");
        
    unlink($filename);
    endwhile; 
    idk how to go about the deleting of the files. i tried unlink and unset.
    as you can see i even chmod the file to 0777.

    Once i get the basics down... ill be able to be more creative...
    Last edited by PlaGuE; Nov 11th, 2005 at 03:40 AM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: fread/fwrite help

    Does it come up with an error message? Maybe the include call which opens that file maintains a lock on the file until the PHP process have finished.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: fread/fwrite help

    again... after i leave it alone... it fixes itself...

    *** IS UP WITH THAT?.lol
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

Posting Permissions

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



Click Here to Expand Forum to Full Width