首先,我声明变量来获取文件夹,并将文件放入数组中。见下文
$DOCROOT = $_SERVER['DOCUMENT_ROOT'];
$dir = $DOCROOT . '/php/pagamentos/resources/pagamentos';
echo ($dir);
$folder = array_diff(scandir($dir), array('.', '..'));
我有以下数组要循环:
array(4) {
[2]=>
string(33) "BMEPS_out22002508200201095005.txt"
[3]=>
string(33) "BMEPS_out22002508200204112009.txt"
[4]=>
string(33) "BMEPS_out22002508200204125012.txt"
[5]=>
string(33) "BMEPS_out22002508200205063000.txt"
}
然后我开始使用以下代码循环数组
foreach ($folder as $file) {
$fp = fopen($file, "r") or die("Unable to open file!");
echo $file;
fclose($fp);
}
但毕竟我收到以下错误:
Warning: fopen(BMEPS_out22002508200204112009.txt): failed to open stream: No such file or directory in /var/www/html/php/pagamentos/index.php on line 40
Unable to open file!
子衿沉夜
相关分类