【发布时间】:2017-04-02 04:29:12
【问题描述】:
我正在尝试使用 PHP copy() 函数将远程文件复制到本地路径。
// https://d47lev3ki2x1o.cloudfront.net/5804aaa8-e5a8-484a-9c3b-4a72c0a83865-1.jpg
$imageURL = Configure::read('cloudfront') . $photo['image_location'];
$localURL = $this->webroot . 'img/tmp/' . $photo['image_location'];
if(!@copy($imageURL, $localURL)) {
$errors= error_get_last();
echo "COPY ERROR: ".$errors['type'];
echo "<br />\n".$errors['message'];
} else {
echo "File copied from remote!";
}
它一直给我错误:
复制错误:2 复制(/baker-and-co/img/tmp/5804a6a8-9c78-49f2-88cc-49f5c0a83865-1.jpg): 无法打开流:没有这样的文件或目录
tmp 目录已经存在于我的本地,所以我看不出这里有什么问题。我也将 allow_url_fopen 设置为 true。
有什么想法吗?
【问题讨论】:
-
你当前的文件夹是什么?
-
我使用的是CakePHP MVC结构,所以我在
/View/Reports/admin_view.ctp,文件夹位于/webroot/img/tmp