首页 > 解决方案 > 出于安全原因,已禁用 file_put_contents()

问题描述

我将我的 laravel 上传到现有网站的子文件夹中并遇到该问题。

[1] https://imgur.com/dSt1P7Q

我在谷歌上找到了解决方案,但到处都在谈论权限被拒绝或其他问题,但如何解决呢?请指导我。

file_put_contents() has been disabled for security reasons

  public function replace($path, $content)
     {
         // If the path already exists and is a symlink, get the real          vpath...
         clearstatcache(true, $path);

         $path = realpath($path) ?: $path;

         $tempPath = tempnam(dirname($path), basename($path));

         // Fix permissions of tempPath because `tempnam()` creates it with permissions set to 0600...
         chmod($tempPath, 777 - umask());

         file_put_contents($tempPath, $content);

         rename($tempPath, $path);
     }

标签: laravel

解决方案


查看您的 php.ini 文件,并查找disable-functions指令。如果您看到file_put_contents那里列出,那么这就是错误的原因。

file_put_contents从此设置中删除,然后重新启动您的 php 服务。

请参阅PHP 手册中的disable_functions参考


推荐阅读