从响应中删除标头值

时间:2016-11-10 06:50:45

标签: php linux laravel

我有一个laravel系统,我将我的一个响应存储在一个特定的文件中:

$objFile = new Filesystem();
        $path = "files/FileName.php";
        $string = $this->getSlides();
        if ($objFile->exists($path))
        {
            $objFile->put($path,"",$lock = false);
            $objFile->put($path,$string,$lock = false);
            $objFile->getRequire($path);
        }
        else
            return getcwd() . "\n";

现在我使用以下行获取内容:

$objFile = new Filesystem();
        $path = "files/FileName.php";

        if ($objFile->exists($path))
        {
            return Response::json([$objFile->getRequire($path)],200);
        }
        else
            return getcwd() . "\n";

现在发生的事情是,当我将文件存储在服务器上时,会添加一些标题,如:

HTTP/1.0 200 OK
Cache-Control: no-cache
Content-Type:  application/json
Date: Thu, 10 Nov 2016 05:38:08 GMT

后面是我存储的文件,所以当我在前端调用文件时,出现以下错误:

SyntaxError: Unexpected token H in JSON at position 0(…)

当然它希望我有一个json值但是我给它的东西不会像1那样开始。任何想法我怎么能在php级别删除它?

2 个答案:

答案 0 :(得分:1)

您使用错误的方法获取文件内容 $objFile->getRequire($path) - 它将执行以下代码块:return require $path;。您必须使用$objFile->get($path)来获取文件内容。

答案 1 :(得分:0)

对不起,我在检索结果时犯了一些错误: 在我使用的getSlides方法中:

return Response::json([
      'Data' => $final_array
  ],200);

现在我将其替换为:

$final_array2 = array(
      'Data' => $final_array
      );
  return json_encode($final_array2);

很抱歉,因为我没有提供此代码,因此没有人会有任何想法

相关问题