...

View Full Version : problem with function file



nst
02-15-2006, 07:34 AM
I have a file_list.txt which contains 3 lines


20050104.txt
20050105.txt
20050107.txt

Each of the lines are the contents of a directory. First I get the filenames and then I want to get the content of each file by using file($filename[$i]), but I get the following error


Warning: file(20050104.txt ): failed to open stream: Invalid argument in .....

How can this be done?


<?php

$filename = file('file_list.txt');
$l_count = count($filename);

for($i = 0; $i < $l_count; $i++)
{
echo $filename[$i]."<BR>";
$filecontent = file($filename[$i]);
}


?>

Zegg90
02-15-2006, 09:52 AM
Maybe you need quotation marks?
You could try that

nst
02-15-2006, 10:53 AM
Maybe you need quotation marks?
You could try that

Where to put them exactly?

MRMAN
02-15-2006, 11:44 AM
it could also be you aren't stripping the guff at the end of the line.
basically as you have the file names on new lines changes are there is a new line code at the end of the text. Also by looks of it there is a space at the end. file(20050104.txt )
what you could to is


$filecontent = file(rtrim($filename[$i]));

nst
02-16-2006, 01:01 PM
Right! Actually 'trim' worked too.


$filecontent = file(trim($filename[$i]));

mlse
02-16-2006, 01:14 PM
Hi nst,

here's my two cents worth: if you are simply reading files from a local directory, have you considered using scandir (http://uk2.php.net/manual/en/function.scandir.php)? My appologies if that isn't what you want, just thought I'd mention it!

Mike.

nst
02-17-2006, 02:03 PM
Hi nst,

here's my two cents worth: if you are simply reading files from a local directory, have you considered using scandir (http://uk2.php.net/manual/en/function.scandir.php)? My appologies if that isn't what you want, just thought I'd mention it!

Mike.

Didn't think of that. It sounds a good idea, thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum