【发布时间】:2013-05-04 02:07:31
【问题描述】:
我遵循this question 中的选定答案,我正在尝试将某个变量的内存中的内容导出到 .php 文件。然后我后来 require_once 生成的 php 文件。
问题是 php 文件永远不会被创建。所以当我尝试要求它时,我得到一个错误(HTTP 500,因为代码取决于这个变量并且因为这个文件不存在)。
错误日志显示该文件不能被要求,因为没有这样的文件或目录。
我试图在其中创建文件的目录有 755 个权限。
这是我用来将变量导出到文件的代码:
$variable_export = var_export($elasticaObject, true);
$variable = "<?php\n\n\$$elasticaObject = $variable_export;\n\n?>";
file_put_contents('theIndex.php', $variable);
知道我做错了什么以及为什么没有生成文件 theIndex.php 吗?
【问题讨论】:
-
file_put_contents的返回值是多少? -
theIndex.php是否已经存在?目录可能是 755,但如果 theIndex.php 已经存在并且由其他用户拥有,那么您仍然无法覆盖它。 -
@andrewsi 如何从 file_put_contents 获取返回值?
-
@MarcB 不,它不存在。
-
@IMUXIxD
$myval = file_put_contents('theIndex.php', $variable); var_dump($myval);这会告诉你写入的字节数,如果失败则返回 false。
标签: php file permissions file-permissions