faqts : Computers : Programming : Languages : PHP : Common Problems : Files

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 6 people (67%) answered Yes
Recently 3 of 5 people (60%) answered Yes


i am trying to read the content of a text file right after creating it. the file exists, but to php, it's empty.

Mar 7th, 2002 04:48
Paul Gault, Guest,

hope this helps, 3 seemed to work correctly
/*  the contents of the file to be read, users/rashid.txt, are
    rashid,rere,as,as  */
$fileText="rtrterte";       //give string any initial value
print("<p> 1. file contents are $fileText");      //show it
$fp=fopen("users/rashid.txt","r"); // open file for reading
$filename = "users/rashid.txt";    //string containing filename
if($fp){  //if file opened succesfully
   $fileText=fread ($fp,filesize($fp)); //read file using filesize arg 
as $fp
   print("<p> 2. file contents are $fileText"); 
   $fileText=fread ($fp,filesize($filename)); //read file using 
filesize arg as $filename
   print("<p> 3. file contents are $fileText");
   $fileText=fread ($fp,1024); //read 1024 bytes
   print("<p> 4. file contents are $fileText");
   print"<p>false"; //file failed to open