외부 이미지 서버에 저장하기 > PHP

STUDY ROOM

PHP

외부 이미지 서버에 저장하기

페이지 정보

작성자 JMStudy 작성일19-01-16 12:29 조회8,149회 댓글0건

본문

function save_remote_image($url, $save_path)

{

    $ch = curl_init ($url);

    curl_setopt($ch, CURLOPT_HEADER, 0);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    $data=curl_exec($ch);

    curl_close ($ch);

$chars_array = array_merge(range(0,9), range('a','z'), range('A','Z'));

$filename = preg_replace("/\.(php|phtm|htm|cgi|pl|exe|jsp|asp|inc)/i", "$0-x", basename($url));

shuffle($chars_array);

$shuffle = implode("", $chars_array);

$change_filename = abs(ip2long($_SERVER[REMOTE_ADDR])).'_'.substr($shuffle,0,8).'_'.str_replace('%', '', urlencode(str_replace(' ', '_', $filename))); 

$out_path = $save_path.$change_filename;

    if(file_exists($out_path)) @unlink($out_path);

    $fp = fopen($out_path,'x');

    fwrite($fp, $data);

    fclose($fp);

return $change_filename;

}

 

 

 

 

 

 

 

댓글목록

등록된 댓글이 없습니다.