2016-11-18 1 views
2

PHP copy() 기능을 사용하여 원격 파일을 로컬 경로로 복사하려고합니다. 그래서 문제가 여기에 무엇을 볼 수 없습니다PHP가 원격 파일을 복사 할 수 없습니다.

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

tmp 디렉토리 내 로컬에 이미 존재합니다

// 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([email protected]($imageURL, $localURL)) { 
    $errors= error_get_last(); 
    echo "COPY ERROR: ".$errors['type']; 
    echo "<br />\n".$errors['message']; 
} else { 
    echo "File copied from remote!"; 
} 

것은 그것은 나에게 오류를주는 유지합니다. 나는 allow_url_fopen도 사실로 설정했습니다.

아이디어가 있으십니까?

+0

현재 폴더는 무엇입니까? –

+0

나는/View/Reports/admin_view.ctp'에 있고 폴더는'/ webroot/img/tmp'에있다. CakePHP MVC 구조를 사용하고있다. – user3574492

답변

0

원격 파일을 사용할 수 없으므로이 방법을 사용하여 새 파일을 만들 수 있습니다.

$imageURL = Configure::read('cloudfront') . $photo['image_location']; 
$localURL = $this->webroot . 'img/tmp/' . $photo['image_location']; 
if(!file_put_contents($localURL, file_get_contents($imageURL));) { 
$errors= error_get_last(); 
echo "COPY ERROR: ".$errors['type']; 
echo "<br />\n".$errors['message']; 
} else { 
echo "File copied from remote!"; 
} 
+0

원격 파일을 복사 할 수있는 가장 확실한 방법은 [docs] (http://php.net/manual/en/function.copy.php),이 코드는 동일한 오류를 나타냅니다. – user3574492

+0

http://stackoverflow.com/questions/9843933/copy-file-from-remote-server-or -url –

+0

그 링크는 내가 시도한 것입니다. copy()는 소스 파일에는 URL을 사용할 수 있지만 대상에는 사용할 수 없습니다. 그래서 다시 URL과 TO 내 로컬 파일 경로에서 복사 할 때이 도움이되지 않습니다. – user3574492

관련 문제