팁자료실에 있는 외부이미지 저장할수 있는 소스인데요..!
(출처, untitle님)의 자료구요..!
기존에 타홈페이지에서 사진을 잘 복사 붙여넣기 했었는데 ㅠㅠ
한사이트에서 될때있고 안될때가 있는데요..!
혹시 아래 코드에서 어디쪽을 수정해야하는지 알수있을까요..
제가 초보라 자세히좀 부탁드릴게요..
Copy
<?php//ver1.0 150410 @_untitle_d 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;} if ($w == '' || $w == 'r'){ $data_dir = G5_DATA_PATH.'/file/'.$bo_table.'/'; $data_url = G5_DATA_URL.'/file/'.$bo_table.'/'; $img_content = str_replace(">", ">", str_replace("<", "<", stripslashes($_POST[wr_content]))); $patten = "/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i"; preg_match_all($patten, $img_content, $match); if ($match[1]) { foreach ($match[1] as $link) { $url = parse_url($link); if ($url[host] && $url[host] != $_SERVER[HTTP_HOST]) { $img_content = str_replace($link, ($data_url.save_remote_image($link, $data_dir)), $img_content); } } $sql = "update ".$write_table." set wr_content = '".sql_real_escape_string(trim($img_content))."' where wr_id = '".$wr_id."'";sql_query($sql); } } ?>
|
답변 2개
채택된 답변
+20 포인트
2017-01-03 (화) 09:47:39
보통 안되는 경우는
외부사이트에서 리퍼러를 체크하던가 쿠키를 체크해서 안될겁니다
2017-01-03 (화) 09:50:09
제 생각에는 이미지 서버가 nginx 일 것 같고 외부 이미지 링크를 허용안하는 듯 보입니다.
그냥 예상일 뿐입니다.
답변을 작성하려면 로그인이 필요합니다.