2012-07-20 2 views
0

이미지가있는 URL이 있습니다 : http://www.example.com/image.jpg
그리고 사용자 입력에 의해 서버에 파일을 업로드하는 작업이 컨트롤러에 있습니다. 나는 URL로 파일을 업로드 할 때 이와 동일한 조치를 취하고 싶다. 지금은 컨트롤러에 $의 ​​RAWDATA를 보내 어떻게컨트롤러에 말림이있는 파일을 보내는 방법

$url = "http://www.example.com/image.jpg"; 
$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); 
$rawdata=curl_exec($ch); 
curl_close ($ch); 

업로드 일반 사용자처럼 처리 할 : 나는 이미지에서 데이터를하기 시작?

감사합니다.

+0

http://stackoverflow.com/questions/1692186/image-upload-using-php-curl이 도움이 될 수 있습니다. –

답변

0

나는 그것을 알아 냈습니다. 컨트롤러에서

$url = "http://www.example.com/image.jpg"; 
$filename = basename($url, rand_string(7)); 
$path = realpath("../webroot/uploads/")."/".$filename; 


$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); 
$rawdata=curl_exec($ch); 
curl_close ($ch); 

if(file_exists($path)){ 
    unlink($path); 
} 

$file = fopen($path, 'x'); 

fwrite($file, $rawdata); 
fclose($file); 


$post_data['Filedata'] = '@'.$path; 
$url = "http://localhost/controller/action"; 
$ch = curl_init(); 
// Set URL on which you want to post the Form and/or data 
curl_setopt($ch, CURLOPT_URL, $url); 
// Data+Files to be posted 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
// Pass TRUE or 1 if you want to wait for and catch the response against the request made 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
// For Debug mode; shows up any error encountered during the operation 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
// Execute the request 
$response = curl_exec($ch); 

echo $response; 

:

function action(){ 

    //get properties of the file 
    //$_FILES['Filedata']['name']; 
    //$_FILES['Filedata']['size']; 
    //$_FILES['Filedata']['tmp_name']; 
    //savefile(); 



} 

사람이 좋을 것입니다 저장하지 않고 파일을 게시하는 방법을 알고있는 경우

.

관련 문제