I am trying to copy a remote file to a local path using the PHP copy()
function.
// 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!";
}
It keeps giving me the error:
COPY ERROR: 2 copy(/baker-and-co/img/tmp/5804a6a8-9c78-49f2-88cc-49f5c0a83865-1.jpg): failed to open stream: No such file or directory
The tmp
directory exists already on my local so I don't see what the issue is here. I have allow_url_fopen
set to true also.
Any ideas?