>  기사  >  백엔드 개발  >  一段PHP代码结果有关问题

一段PHP代码结果有关问题

WBOY
WBOY원래의
2016-06-13 10:18:15809검색

一段PHP代码结果问题

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $DBserver = "localhost";$DBname = "lookdb";$DBuser = "root";$DBpassword = "";$con = mysql_connect("localhost","root","");mysql_select_db("lookdb");function listDir($dir){    if (is_dir($dir)){        if($dh = opendir($dir)){            while(($file = readdir($dh))!== false){                if((is_dir($dir."/".$file))&&$file!="."&&$file!=".."){                    echo "<b><font color="red">文件名:</font>",$file,"<br><hr>";                    listDir($dir."/".$file."/");                }                else{                    if($file!="."&&$file!=".."){                        echo $file." ";                        $arr = explode(" ",$file);                                                print_r($arr);                                                $sql = "insert into pdfcontents (pdf_title) value ('{$arr}')";                    }                }            }            closedir($dh);        }    }    return ($file);}listDir("C:/AEED/PHPnow/htdocs/2003Z/nz/");?>



结果:
nz01.pdf Array ( [0] => nz01.pdf ) nz02.pdf Array ( [0] => nz02.pdf ) nz03.pdf Array ( [0] => nz03.pdf ) nz04.pdf Array ( [0] => nz04.pdf ) nz05.pdf Array ( [0] => nz05.pdf ) nz06.pdf Array ( [0] => nz06.pdf ) nz07.pdf Array ( [0] => nz07.pdf ) nz08.pdf Array ( [0] => nz08.pdf ) nz09.pdf Array ( [0] => nz09.pdf ) nz10.pdf Array ( [0] => nz10.pdf ) nz11.pdf Array ( [0] => nz11.pdf ) nz12.pdf Array ( [0] => nz12.pdf ) nz13.pdf Array ( [0] => nz13.pdf ) nz14.pdf Array ( [0] => nz14.pdf ) nz15.pdf Array ( [0] => nz15.pdf ) nz16.pdf Array ( [0] => nz16.pdf ) nz17.pdf Array ( [0] => nz17.pdf ) nz18.pdf Array ( [0] => nz18.pdf ) nz19.pdf Array ( [0] => nz19.pdf ) nz20.pdf Array ( [0] => nz20.pdf ) nz21.pdf Array ( [0] => nz21.pdf ) nz22.pdf Array ( [0] => nz22.pdf ) nz23.pdf Array ( [0] => nz23.pdf ) nz24.pdf Array ( [0] => nz24.pdf ) nz25.pdf Array ( [0] => nz25.pdf ) nz26.pdf Array ( [0] => nz26.pdf ) nz27.pdf Array ( [0] => nz27.pdf ) nz28.pdf Array ( [0] => nz28.pdf ) nz29.pdf Array ( [0] => nz29.pdf ) nz30.pdf Array ( [0] => nz30.pdf ) nz31.pdf Array ( [0] => nz31.pdf ) nz32.pdf Array ( [0] => nz32.pdf ) nz33.pdf Array ( [0] => nz33.pdf ) nz34.pdf Array ( [0] => nz34.pdf ) nz35.pdf Array ( [0] => nz35.pdf ) nz36.pdf Array ( [0] => nz36.pdf ) nz37.pdf Array ( [0] => nz37.pdf ) nz38.pdf Array ( [0] => nz38.pdf ) nz39.pdf Array ( [0] => nz39.pdf ) nz40.pdf Array ( [0] => nz40.pdf ) nz41.pdf Array ( [0] => nz41.pdf ) nz42.pdf Array ( [0] => nz42.pdf ) nz43.pdf Array ( [0] => nz43.pdf ) nz44.pdf Array ( [0] => nz44.pdf ) nz45.pdf Array ( [0] => nz45.pdf ) nz46.pdf Array ( [0] => nz46.pdf ) nz47.pdf Array ( [0] => nz47.pdf ) nz48.pdf Array ( [0] => nz48.pdf ) nz49.pdf Array ( [0] => nz49.pdf ) nz50.pdf Array ( [0] => nz50.pdf ) nz51.pdf Array ( [0] => nz51.pdf ) nz52.pdf Array ( [0] => nz52.pdf ) nz53.pdf Array ( [0] => nz53.pdf ) nz54.pdf Array ( [0] => nz54.pdf ) nz55.pdf Array ( [0] => nz55.pdf ) nz56.pdf Array ( [0] => nz56.pdf ) nz57.pdf Array ( [0] => nz57.pdf ) nz58.pdf Array ( [0] => nz58.pdf ) nz59.pdf Array ( [0] => nz59.pdf ) nz60.pdf Array ( [0] => nz60.pdf ) 

我只是想把目录里的文件名都分条存入数据库呀。这样存不进去.

------解决方案--------------------
呵呵,看错眼啦

$sql = "insert into pdfcontents (pdf_title) value ('{$arr}')";

$arr是explode的数组吧,不带这样执行的,,你希望保存什么吧

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.