Basic PHP help...

Discussion in 'OT Technology' started by MacandCheese, Dec 7, 2003.

  1. MacandCheese

    MacandCheese Mmm Mmmm Goood ;)

    Joined:
    Oct 9, 2002
    Messages:
    208
    Likes Received:
    0
    Location:
    USA
    Hey guys,

    Need alittle basic help. I've read, what feels like a thousand webpages tonight on php with not much helping me.

    What i want to do is this. Say i go to a website: http://www.website.com/index.php?name=cheese . I want the "cheese" to be written into a text file. That's it.

    Sounds easy but i have not been able to come up with anything in the past 3 hour sof searching.

    Thanks for your help! :)
     
  2. Divine Vengeance

    Divine Vengeance New Member

    Joined:
    May 21, 2003
    Messages:
    20,453
    Likes Received:
    0
    Code:
    <?
    
        $name = $_GET['name'];
    
        $file = "name.txt";								
    						
        touch($file); 	// Create blank file
        chmod($file, 0666);	// CHMOD it
    		
        fwrite( $file, $name );   // write $name to file
    
    ?>
    
    
     
  3. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    Hmm... touch() and chmod() are rather low level...

    MacandCheese: Take a browse at fopen() and its instructions. It gives you a lot of options.

    http://us3.php.net/manual/en/function.fopen.php

    Example:

    PHP:
    $name $_GET['name'];  // might want to validate this to make sure it isn't funky

    $fp fopen('name.txt''w');  // open file for writing, create if doesn't exist
    fputs($fp$name);  // write the string to the file
    fclose($fp);  // a little house cleaning - close the file
    Divine's approach will work too. But I'd recommend using fopen(), fclose(), etc. PHP by default will create the file with the proper rights unless your host is wacky. You don't need to issue the touch() command with fopen().
     
  4. Divine Vengeance

    Divine Vengeance New Member

    Joined:
    May 21, 2003
    Messages:
    20,453
    Likes Received:
    0
    heh, i just ripped mine out of an old script I wrote, I didn't feel like writing something new :hs:
     

Share This Page