在CakePHP中的file_put_content()中指定相对路径服务器



我一直在寻找一种方法,将相对路径放入PHP的file_put_content()函数中。基本上,我想将一个文件复制到服务器的某个目录中。以下是我迄今为止所做的:

function curl($url){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            $data = curl_exec($ch);
            curl_close($ch);
            return $data;
        }
        $image_new = curl($image);
        file_put_contents("/minimaled_server_path/app/webroot/logo_url",
                          $image_new);

它给我带来了以下错误:

file_put_contents(/minimal_server_path/app/webroot/logo_url)
  [function.file-put-contents]:
failed to open stream: No such file or directory
  [APP/Controller/AppsController.php, line 105]

我在这里错过了什么?

尝试使用realpath函数从执行函数的文件中计算路径

file_put_contents(realpath("/../../minimaled_server_path/app/webroot/logo_url"), $image_new);

相关内容

最新更新