可以“检索”子目录中的文件内容

时间:2014-05-31 02:51:22

标签: php file-get-contents

我有一个代码可以处理一些包含数据的txt文件 该文件将数据插入到数据库中,其中包含更多详细信息 问题是当我将 glob()添加到等式中时(因此它可以处理名为data的目录中的所有数据文件)
我遇到了 file_get_contents的问题( )功能 这是我使用的代码:

    <?php
//Database connect 
$sql = new mysqli('localhost','root','','torrents+');
foreach(glob("data/*.txt") as $file) {
$filename = substr($file, 5,-4);

//Get Data
$text = file_get_contents('/'.$file.'');



foreach(explode("\n", $text) as $line) {
$data = explode("|", $line);
$magnet = $data[0];
$name = $data[1];
$magnet = "magnet:?xt=urn:btih:".$magnet."&dn=".$name."";

//Variables definition
$Name = $name;
$Category = $filename;
$Size = "_";
$date = time();
$Seed = "_";
$Leech = "_";
$hits = "0";


//Insert
$query = "INSERT INTO `torrents` (id, name, category, size, date, seed, leech, magnet, hits) VALUES (' ','$name','$Category','$Size','$date','$Seed','$Leech','$magnet','$hits');";
$sql->query($query) or die($query.'<br />'.$sql->error);

}



echo "<h1>Done with file ".$file." !!!!</h1>";
}

?>

以下是我得到的错误:

Warning: file_get_contents(/data/Games Mac.txt): failed to open stream: No such file or directory in C:\...\localweb\Scripts\handle.php on line 8


Warning: file_get_contents(/data/Games Mobile.txt): failed to open stream: No such file or directory in C:\...\localweb\Scripts\handle.php on line 8

0 个答案:

没有答案