help with code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PatrickL
Forum Newbie
Posts: 4
Joined: Fri Jan 07, 2005 8:43 am

help with code

Post by PatrickL »

what I am trying to do here is to create a folder which
is named after a persons ip address and then write to a file in that folder
This code is successful at creating the folder and writes to
a file , however the file sits outside the persons folder

Code: Select all

<?php
$file= $_ENV['REMOTE_ADDR'];  


mkdir("./$file", 0777);


function WriteToFile($strFilename, $strText)  
{  
      if($fp = @fopen($strFilename,"w "))  
     {  
          $contents = fwrite($fp, $strText);  
          fclose($fp);  
          return true;  
      }else{  
          return false;  
      }  

  }  
  
  WriteToFile('test.txt','test 123');  
?>
Thanks in advance for your help!!


feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

<?php 
$file= $_ENV['REMOTE_ADDR'];  


mkdir("./$file", 0777); 


function WriteToFile($strFilename, $strText)  
{  
      if($fp = @fopen($strFilename,"w "))  
     {  
          $contents = fwrite($fp, $strText);  
          fclose($fp);  
          return true;  
      }else{  
          return false;  
      }  

  }  
  
  WriteToFile('./'.$file.'/test.txt','test 123');  
?>
$file is the IP of the person so that is the name of the directory. Therefore when you write to the file text.txt you need to ensure it's in the same directory you just created ./IP Address/test.txt
PatrickL
Forum Newbie
Posts: 4
Joined: Fri Jan 07, 2005 8:43 am

thanks it's great

Post by PatrickL »

:P
PatrickL
Forum Newbie
Posts: 4
Joined: Fri Jan 07, 2005 8:43 am

just one other issue

Post by PatrickL »

I should have ask before
this will write to the text file....
test 123

how can I write to the text file like so
test 123 line break here
test 456

I have tried
WriteToFile('./'.$file.'/test.txt','test 123 /n test 456'); ?>
but that just doesn't do it
help again please


Code: Select all

<?php $file= $_ENV['REMOTE_ADDR'];  mkdir("./$file", 0777); function WriteToFile($strFilename, $strText)  {        if($fp = @fopen($strFilename,"w "))       {            $contents = fwrite($fp, $strText);            fclose($fp);            return true;        }else{            return false;        }    }      WriteToFile('./'.$file.'/test.txt','test 123');  ?>

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color][/size]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

read the strings documentation on php.net

\n is a carriage return.. but only in a double quoted string.
PatrickL
Forum Newbie
Posts: 4
Joined: Fri Jan 07, 2005 8:43 am

I solve it

Post by PatrickL »

a few hours of searching though....
each time I need a new line..... a line break will
be created everytime I hit enter on the key board
would never of thought that :oops:
Post Reply