Warning: fopen(access.log) [function.fopen]: failed to open stream: No such file or directory in /var/www/html_leyu/admin_platform/adm/log_import.php on line 33 Call Stack # Time Memory Function Location 1 0.0186 74652 {main}( ) ../log_import.php:0 2 0.0287 577416 fopen ( ) ../log_import.php:33boolean false
然后for循环file_get_contents读取文件内容
(PHP 4 >= 4.3.0, PHP 5)glob -- 寻找与模式匹配的文件路径
说明
array glob ( string pattern [, int flags] )
glob() 函数依照 libc glob() 函数使用的规则寻找所有与 pattern 匹配的文件路径,类似于一般 shells 所用的规则一样。不进行缩写扩展或参数替代。 返回一个包含有匹配文件/目录的数组。如果出错返回 FALSE。
$file_name = scandir($dir,1);
for($i = 0; $i < count($file_name); $i++){
$filename = "$file_name[$i]"; //文件名及地址
$fp = fopen($filename,"r"); //打开文件
var_dump($fp);
exit;
提示 Warning: fopen(access_14.log) [function.fopen]: failed to open stream: No such file or directory in /var/www/html_leyu/admin_platform/adm/log_import.php on line 25为什么?
$filename = "$file_name[$i]"; //文件名及地址
if($filename !='.' && $filename!='..')
{
$fp = fopen($filename,"r"); //打开文件
var_dump($fp);
}提示打开不存在的文件 你自己print_r($file_name); 这个数组看下就明白
Call Stack
# Time Memory Function Location
1 0.0186 74652 {main}( ) ../log_import.php:0
2 0.0287 577416 fopen ( ) ../log_import.php:33boolean false
{
$str=str_replace('/',' ',substr($str,1));
$str=preg_replace('/:/',' ',$str,1);
$str1 = date('Y-m-d H:i:s',strtotime($str));
return $str1;
} $dir = './log';
$file_name = scandir($dir,1);
$datestart = strtotime("2010-11-11 14:30:00");
$datestop = strtotime("2010-11-25 21:00:00");
for($i = 0; $i<count($file_name); $i++)
{
$filename = "$file_name[$i]"; //文件名及地址
if($filename !='.' && $filename !='..')
{
$fp = fopen($filename,'r'); //打开文件
var_dump($fp);
eixt;
while($fps = fgetcsv($fp,4096," "))
{
print_r($fps);
exit;
preg_match_all('/[\?&]([^=]+?)=([^&]+)/',$fps[5],$matches);
$match=array_combine($matches[1],$matches[2]);
$username = iconv('gb2312', 'utf-8', rawurldecode($match['username'])); //字符解码
$datetime = datestr($fps["3"]);
$sql = "";
if( ($match["ctype"]==8) && (!isset($match["status"])) && (($datestart < strtotime($fps["0"])) < $datestop) )
{
$sql = "INSERT INTO t_music_downloadcount(music_id,userid,ip,phoneid,status,downloadstatus,downloadtime,successtime)
SELECT '{$match["contentid"]}',userid,'{$fps[0]}', '{$match["phoneid"]}', '2', '1','{$datetime}', '{$datetime}'
FROM t_olebar_user
WHERE username ='{$username}' ";
}
$pq->conn->Execute($sql);
}
fclose($filename); //关闭文件
}
}
echo file_get_contents("test.txt");
?>
$filename = $dir."$file_name[$i]";//文件名及地址
$filename = $dir."/$file_name[$i]";//文件名及地址