Re: [PHP] PHP script + read file
What is wrong with this code? Why $input_str is empty. if ($handle = opendir('/home/test2/')) { echo Directory handle: $handle\n; echo Files:\n; while (false !== ($file = readdir($handle))) { if($file != . $file != ..){ $handle1 = fopen($file, a+); $input_str = fread($handle1, filesize($file)); echo TEST.$input_str; } } } On Sun, 21 Nov 2004 05:40:07 +0800, Jason Wong [EMAIL PROTECTED] wrote: On Sunday 21 November 2004 05:11, Jerry Swanson wrote: I know how to read a file. But the problem is different, I have directory that has more than 250 files. I need to read each file and process it. But How I know what file to read? ls -l (show all files). How I can select each file without knowing name? The file will be process and than delete. To get list of files from directory: manual Directory Functions To open/read/write/delete files: manual Filesystem Functions There are plenty of examples in the manual and in the user notes of the online manual. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Do not try to solve all life's problems at once -- learn to dread each day as it comes. -- Donald Kaul */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script + read file
On Sunday 21 November 2004 20:25, Jerry Swanson wrote: Please do not top post. What is wrong with this code? Why $input_str is empty. if ($handle = opendir('/home/test2/')) { echo Directory handle: $handle\n; echo Files:\n; while (false !== ($file = readdir($handle))) { if($file != . $file != ..){ $handle1 = fopen($file, a+); $input_str = fread($handle1, filesize($file)); echo TEST.$input_str; } } } The $file that you're trying to open is in the directory '/home/test2/', as your working directory is not the same (getcwd()) you would have to specify the full path to $file, ie prepend '/home/test2/'. You would have been able to deduce this yourself had you looked at the php error log. Always develop with: error_reporting(E_ALL); ini_set('display_errors', TRUE); -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Knghtbrd If I start writing essays about Free Software for slashdot, please shoot me. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP script + read file
I know how to read a file. But the problem is different, I have directory that has more than 250 files. I need to read each file and process it. But How I know what file to read? ls -l (show all files). How I can select each file without knowing name? The file will be process and than delete. Any ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script + read file
Jerry Swanson wrote: I know how to read a file. But the problem is different, I have directory that has more than 250 files. I need to read each file and process it. But How I know what file to read? ls -l (show all files). How I can select each file without knowing name? The file will be process and than delete. Any ideas? Something like this? $dp = opendir('dirname'); while ($file = readdir($dp)) { // Process file, filename $file } closedir($dp); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script + read file
On Sat, Nov 20, 2004 at 09:11:41PM +, Jerry Swanson wrote: I know how to read a file. But the problem is different, I have directory that has more than 250 files. I need to read each file and process it. But How I know what file to read? ls -l (show all files). How I can select each file without knowing name? The file will be process and than delete. Look at http://www.php.net/manual/en/function.opendir.php /GM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP script + read file
On Sunday 21 November 2004 05:11, Jerry Swanson wrote: I know how to read a file. But the problem is different, I have directory that has more than 250 files. I need to read each file and process it. But How I know what file to read? ls -l (show all files). How I can select each file without knowing name? The file will be process and than delete. To get list of files from directory: manual Directory Functions To open/read/write/delete files: manual Filesystem Functions There are plenty of examples in the manual and in the user notes of the online manual. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Do not try to solve all life's problems at once -- learn to dread each day as it comes. -- Donald Kaul */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php