Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Can';检索子目录中文件的内容_Php_File Get Contents - Fatal编程技术网

Php Can';检索子目录中文件的内容

Php Can';检索子目录中文件的内容,php,file-get-contents,Php,File Get Contents,我有一个代码可以处理一些包含数据的txt文件 该文件将数据插入数据库,并提供更多详细信息 问题是,当我将glob()添加到等式中时(这样它可以处理名为data的目录中的所有数据文件)我遇到了file\u get\u contents()函数的问题 以下是我使用的代码: <?php //Database connect $sql = new mysqli('localhost','root','','torrents+'); foreach(glob("data/*.txt") a

我有一个代码可以处理一些包含数据的txt文件
该文件将数据插入数据库,并提供更多详细信息
问题是,当我将glob()添加到等式中时(这样它可以处理名为data的目录中的所有数据文件)
我遇到了file\u get\u 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>";
}

?>

由于文件名中有空格,windows要求有引号,所以我应该更改什么正如Dagon指出的,因为它有空格,所以您需要引号:try
(“/”.$file.“)
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