Forum Moderators: coopster

Message Too Old, No Replies

Problem reading textfile

Even after chmod -R 777 / :(

         

Xavier

2:20 am on Dec 19, 2004 (gmt 0)



<?php
$progdatabase = '/var/www/data/programs.data';
if(!file_exists($progdatabase))
die("Database doesn't exist");
if(!is_readable($progdatabase))
die("Database not readable");
if(!is_writable($progdatabase))
die("Database not writable");
$fp = fopen($progdatabase, "r") or die("Couldn't open file");
$data = fread($fp, filesize($fp));
while(!feof($fp)) {
$data .= fgets($fp, 1024);
}
fclose($fp);
?>

I keep getting these error messages!

Warning: filesize(): Stat failed for Resource id #2 (errno=2 - No such file or directory) in /var/www/list.php on line 29
Warning: fread(): Length parameter must be greater than 0. in /var/www/list.php on line 29

I know there is text within the text file too! ggraajj.. The folder data & the file programs.data I KNOW are chmod 777. I just have no clue...

jatar_k

2:27 am on Dec 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what about trying readfile instead of fread?

Xavier

2:45 am on Dec 19, 2004 (gmt 0)



Hey that worked great!

$progdatabase = 'datae/list.data';
if(!file_exists($progdatabase))
die("Database doesn't exist");
if(!is_readable($progdatabase))
die("Database not readable");
if(!is_writable($progdatabase))
die("Database not writable");
readfile($progdatabase);

That's weird...but still, it doesn't give me the text of the file, it just outputs it onto the page :(

jatar_k

4:57 pm on Dec 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



so it isn't the path then

hmm, looking at the code again

$fp = fopen($progdatabase, "r") or die("Couldn't open file");
$data = fread($fp, filesize($fp));
while(!feof($fp)) {
$data .= fgets($fp, 1024);
}

what is the fread line for? You can use the fgets loop by itself to get the data. Why not just this?

$fp = fopen($progdatabase, "r") or die("Couldn't open file");
while(!feof($fp)) {
$data .= fgets($fp, 1024);
}

Xavier

7:43 am on Dec 20, 2004 (gmt 0)



aahhh I didn't know what I was doing lol. I switched to mySQL :). Yeah I think that was the mistake, because the other textfile reading worked, it was just that paragraph of code that didn't. Thanks for the help though :)