fopen/fgets
| From: | Bryan Koschmann - GKT | Date: | Thu, 06 Mar 2003 23:28:47 +0000 |
| Subject: | fopen/fgets | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-138540@lists.php.net to get a copy of this message | ||
Can someone give me a hand here? I am really lost as to what is going on.
I have a file that looks like this
user1,Store 1 - ABC street
user2,Store 2 - Northside
user3,Store 3 - East
I try to run my code, but I get a php log filled (~33 megs, the input file
is only 12 lines):
[06-Mar-2003 15:22:53] PHP Warning: feof(): 1 is not a valid File-Handle
resource in /home/perf/create_prefs.php on line 7
[06-Mar-2003 15:22:53] PHP Warning: fgets(): 1 is not a valid File-Handle
resource in /home/perf/create_prefs.php on line 8
[06-Mar-2003 15:22:53] PHP Warning: feof(): 1 is not a valid File-Handle
resource in /home/perf/create_prefs.php on line 7
[06-Mar-2003 15:22:53] PHP Warning: fgets(): 1 is not a valid File-Handle
resource in /home/perf/create_prefs.php on line 8
While it is running it just stalls.
This is my code:
$fp = fopen("emaillist", "r");
if (!$fp)
die("Error opening file. $php_errormsg");
while (!feof($fp)) {
$buffer = fgets($fp, 4096);
echo $buffer;
$row = explode(',', $buffer);
if (!empty($row[0])) {
$user = "$row[0]";
$name = "$row[1]";
$stuff = "email_address=$user@mystore.com\n" .
"chosen_theme\=../themes/mystore_theme.php\n" .
"show_html_default\=0\n" .
"javascript_on\=1\n" .
"full_name\=$name\n" .
"use_signature\=0\n" .
"prefix_sig\=0\n";
$fileout = $user . "_perf.pref";
$fout = fopen("$fileout", "w");
fputs($fout, "$stuff");
fclose($fp);
fclose($fout);
}
}
Please help! I keep re-reading the docs at php.net for fopen fgets and all
that with no luck!
Thanks,
Bryan