Page 1 of 1

help with code

Posted: Fri Jan 07, 2005 8:54 am
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]

Posted: Fri Jan 07, 2005 9:06 am
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

thanks it's great

Posted: Fri Jan 07, 2005 9:14 am
by PatrickL
:P

just one other issue

Posted: Fri Jan 07, 2005 9:25 pm
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]

Posted: Fri Jan 07, 2005 9:31 pm
by feyd
read the strings documentation on php.net

\n is a carriage return.. but only in a double quoted string.

I solve it

Posted: Fri Jan 07, 2005 10:04 pm
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: