php附加/写入文件

时间:2012-08-01 19:20:24

标签: php append fwrite

我使用以下脚本在include.php文件中写入 此脚本搜索files和images文件夹中的文件,并在include.php中写入 files目录包含文件

*sintel_trailer1.mp4
*sintel_trailer2.mp4

images dir包含以下文件

*sintel_trailer1.jpg
*sintel_trailer2.jpg

php code

$path = array("./files/","./images/");
$path2=      array("http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/files/","http://".$_SERVER['S ERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/images/");
$start="";
$Fnm = "./include.php";
$inF = fopen($Fnm,"w");
fwrite($inF,$start."\n");

$folder = opendir($path[0]);
while( $file = readdir($folder) ) {
       if (($file != '.')&&($file != '..')&&($file != 'index.htm')) {
            $folder2 = opendir($path[1]);
            $imagename ='';
            while( $file2 = readdir($folder2) ) {
                if (strstr($file2, '.', true) == strstr($file, '.', true)){
                    $imagename = $file2;
                }
            }
            closedir($folder2);
        $result="{\nlevels: [\n{ file: \"$path2[$key]$file\" }\n],\nimage: \"$imagename\"\ntitle: \"$file\"\n},\n";
        fwrite($inF,$result);
       }
}
fwrite($inF,"");
closedir($folder);

fclose($inF);

我得到以下结果

{
levels: [
{ file: "sintel_trailer1.mp4" }
],
image: "sintel_trailer2.jpg"
title: "sintel_trailer1.mp4"
},
{
levels: [
{ file: "sintel_trailer2.mp4" }
],
image: "sintel_trailer2.jpg"
title: "sintel_trailer2.mp4"
},

但我需要这个结果

{
levels: [
{ file: "sintel_trailer1.mp4" }
],
image: "sintel_trailer1.jpg"
title: "sintel_trailer1.mp4"
},
{
levels: [
{ file: "sintel_trailer2.mp4" }
],
image: "sintel_trailer2.jpg"
title: "sintel_trailer2.mp4"
},

更新

错误日志显示 警告:第15行index.php中strstr()的参数计数错误

第15行 if(strstr($ file2,'。',true)== strstr($ file,'。',true)){

0 个答案:

没有答案