Page 1 of 1
Trouble with file()
Posted: Wed Jul 10, 2002 2:29 am
by Paul Oertel
I am trying to read a group of text files that contain parts of a report. My code looks like this:
Code: Select all
$fp = fopen("m:\\html_parts\\html02.txt", "r");
$filearray = file($fp);
The following error is returned:
PHP Warning: file() expects parameter 1 to be string, resource given in m:\reportnt_test.php on line 46
I would appreciate help getting over this bump in the road.
Paul
Posted: Wed Jul 10, 2002 2:47 am
by rd64pro
The problem is that both 'fopen' and 'file' open files, with the path to the file specified as a string. I'm not exactly clear on what specifically you wanted out of those two statements, so I'll just give a couple examples:
// this will open the file and return an array of all lines in the file
$contents = file("m:\\html_parts\\html02.txt");
// this, however, only returns a handle to the file specified. After you
// have this handle, you can perform read operations using functions
// such as 'fread', etc.
$fp = fopen("m:\\html_parts\\html02.txt", 'r');
Since you are dealing with straight text here, my guess is you DO want an array of lines from the file, so go with example 1.
I hope this helps!
-Ryan
Posted: Wed Jul 10, 2002 2:50 am
by twigletmac
You don't need to do fopen() in order to use file(), have you tried
Code: Select all
$filearray = file('m:\\html_parts\\html02.txt');
Mac
Posted: Wed Jul 10, 2002 4:47 am
by Paul Oertel
You're right. Thanks for the help everybody.
Paul