HELP!: FOPEN/creating a PHP FILE; How do i do this? Details inside.

Discussion in 'PHP' started by SiteSlangin, Apr 16, 2009.

Thread Status:
Not open for further replies.
  1. #1
    So here's a rundown of what i need to get working :confused::confused:


    When a user registers on my site, i need a file to be instantly created SPECIFICALLY FOR THAT MEMBER.

    This PHP file needs to be made for the member

    <?php
    // Create a new image instance
    $im = imagecreatetruecolor(1, 1);
    
    // Make the background white
    imagefilledrectangle($im, 0, 0, 1, 1, 0xFFFFFF);
    
    // Draw a text string on the image
    imagestring($im, 3, 40, 20, '', 0xFFBA00);
    
    // Output the image to browser
    header('Content-type: image/gif');
    
      $time = time();
    $myFile = "/home/webmast/public_html/MYWEBSITE.com/[b]$username.txt[/b]";
    $fh = fopen($myFile, 'w+b') or die("can't open file");
    $stringData = "lots of stuff here\n";
    fwrite($fh, $stringData); 
    
    
    imagegif($im);
    imagedestroy($im);
    ?>
    
    
    Code (markup):
    I already have the $username variable set. All i need to do is CREATE A PHP FILE with the ABOVE CONTENT per user, just use the $username variable for the .php FILE NAME with the above content, and have the NEWLY CREATED FILE (above content) display THEIR USERNAME under $username.txt )

    Thanks so much to whoever helps me out with this :) Sorry if i made it confusing.
     
    SiteSlangin, Apr 16, 2009 IP
  2. SiteSlangin

    SiteSlangin Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In simpler terms (now that i think about it); THE HELP I NEED FROM YOU DP'ERS:


    The code to CREATE A PHP file named $username.php - username is already defined on my side :)

    That php file will have

    <?php
    // Create a new image instance
    $im = imagecreatetruecolor(1, 1);
    
    // Make the background white
    imagefilledrectangle($im, 0, 0, 1, 1, 0xFFFFFF);
    
    // Draw a text string on the image
    imagestring($im, 3, 40, 20, '', 0xFFBA00);
    
    // Output the image to browser
    header('Content-type: image/gif');
    
      $time = time();
    $myFile = "/home/webmast/public_html/MYWEBSITE.com/[B]$username.txt[/B]";
    $fh = fopen($myFile, 'w+b') or die("can't open file");
    $stringData = "lots of stuff here\n";
    fwrite($fh, $stringData); 
    
    
    imagegif($im);
    imagedestroy($im);
    ?>
    Code (markup):
    With the above created file, it will ALSO have the specific $username in the above bolded part ($username) in the code for the newly created php.


    So basically it needs to create the php file named username.php, and write that username.php accordingly with the $username.txt part in the code
     
    SiteSlangin, Apr 16, 2009 IP
  3. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Why on earth would you want to do this? It will scale poorly and provides no advantage that I can think of.
     
    SmallPotatoes, Apr 16, 2009 IP
  4. nayes84

    nayes84 Member

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    instead of creating the same file for each user just use the same file with enabling url-rewriting in htaccess file.
    for examle when opening $username.php actually it will open phpfile.php?user=$username

    example code:
    RewriteRule ^(.*)\.php$ phpfile.php?user=$1 [L]
     
    nayes84, Apr 17, 2009 IP
Thread Status:
Not open for further replies.