Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.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
file_get_contents($file)在PHP第二次迭代中执行循环时抛出警告_Php_File Get Contents - Fatal编程技术网

file_get_contents($file)在PHP第二次迭代中执行循环时抛出警告

file_get_contents($file)在PHP第二次迭代中执行循环时抛出警告,php,file-get-contents,Php,File Get Contents,我有许多json格式的.txt文件。我试图一个接一个地获取每个文件,修改其内容,然后将这些内容放回文件。为此,我执行了一个循环,对每个文件执行这个过程。循环在第一次迭代中运行完全正常,但在第二次迭代中抛出警告: 警告:file_get_contents../videos/list2.txt[function.file get contents]:无法打开流:第85行D:\wamp\www\dtt_admin_V2\pages\jason2.php中的参数无效 文件\u get\u content

我有许多json格式的.txt文件。我试图一个接一个地获取每个文件,修改其内容,然后将这些内容放回文件。为此,我执行了一个循环,对每个文件执行这个过程。循环在第一次迭代中运行完全正常,但在第二次迭代中抛出警告:

警告:file_get_contents../videos/list2.txt[function.file get contents]:无法打开流:第85行D:\wamp\www\dtt_admin_V2\pages\jason2.php中的参数无效

文件\u get\u contents../videos/list2.txt中的参数正确。这里面没有问题。我不知道是什么导致了这个错误。关于这个错误的任何帮助都是非常诱人的。在下面的代码块中,带有错误的行将突出显示为注释,如/*line*/

$sql = "SELECT * FROM dtt_location";

$result = $conn->query($sql);


if ($result->num_rows > 0) 
{    

while($row = $result->fetch_assoc()){

    $path_text=$row['path_text'];


    //echo "id_for_location".$id_for_location."<br>";

            $file = $path_text;
/*line48 */ $text = file_get_contents($file);

            //echo $text."<br>";
            $someObject = json_decode($text);
            $array_object=objectToArray($someObject);
            $ar_size=sizeof($array_object);
            $count=0;
            $array_name[]="";
            $array_url[]="";
            $skip=0;
            while($count<$ar_size){ 
                $temp_element=$array_object[$count];
                //print_r($temp_element);

                if($temp_element["name"]!=$video_name){
                    $array_name[$skip]=$temp_element["name"];
                    $array_url[$skip]=$temp_element["url"];
                    //$b=$a[0];
                    $skip++;
                }

                else{
                    //echo $count."<br>"."temp"."<br>".$temp_element["name"]."<br>".$temp_element["url"]."<br>";
                    //echo $count."<br>"."selected"."<br>".$video_name."<br>".$path_video."<br>";
                }

                $count++;
            }

            $count=0;
            $ar_si=$ar_size-1;


            //echo $ar_size."<br>";
            //echo $ar_si;
            $create[]="";
            while($count<$ar_si)
             {
                echo $count;

                $create[$count]=$first.$array_name[$count]. $second.$array_url[$count].$third;
                $count++;
            }   


            $create_j=join(",",$create);
            $create_j="[".$create_j."]";

            if($create_j=="[]"){
                //echo "$create_j"."<br>";
                $create_j=$text;
                //echo "$create_j";
                //error_msg_empty_broadcast();
    /*Line 108 */           file_put_contents($file, $create_j);
            }//echo $create_j."<br>";               
            else
            {
                file_put_contents($file, $create_j);


        }   
    }

我猜在你的文件路径文本中有一些特殊的字符,比如[space]。您需要使用trim删除路径\文本周围的空格,并对路径\文本进行编码


*详细信息如下:

我正在WAMP上运行它,请确保文件名$path\u text=trim$row['path\u text']周围没有空格;请确认文件是否存在