Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.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 文件\u获取\u控制器内的内容不在prestashop中工作_Php_Controller_Prestashop_File Get Contents_Prestashop 1.6 - Fatal编程技术网

Php 文件\u获取\u控制器内的内容不在prestashop中工作

Php 文件\u获取\u控制器内的内容不在prestashop中工作,php,controller,prestashop,file-get-contents,prestashop-1.6,Php,Controller,Prestashop,File Get Contents,Prestashop 1.6,我试图访问控制器内的文件内容 $data= file_get_contents($this->module->getPath()."data/file.json"); print_r(var_dump($data)); var_dump输出给出booleanfalse。如何访问文件的内容?我想指出的是,您的路径错误 print_r($this>->module->getPath() . "data/file.json"); 这将输出:yourModuleNa

我试图访问控制器内的文件内容

 $data= file_get_contents($this->module->getPath()."data/file.json");
 print_r(var_dump($data));

var_dump输出给出booleanfalse。如何访问文件的内容?

我想指出的是,您的路径错误

print_r($this>->module->getPath() . "data/file.json");
这将输出:yourModuleName/data/file.json

但是您的控制器位于controller/admin中/

因此,它将在controller/admin/yourModuleName/data/file.json中搜索该文件

也许可以尝试以下未经测试的方法:

"/../../".$this>->module->getPath()."data/file.json"

检查var_dump$this->module->getPath.data/file.json并确保该文件存在,并且PHP/webserver用户可以读取该文件。该文件就在那里,当我使用print$this->module->getPath.data/file.json打印时,我可以使用相同的路径从浏览器访问该文件。它给了您什么值?如果您可以使用它提供的值从浏览器访问它,那么它在服务器文件系统上的路径似乎不太可能相同。无论哪种方式,文件内容都只会在出现错误时返回false。