다시한번 질문좀 드릴게요..!

다시한번 질문좀 드릴게요..!

QA

다시한번 질문좀 드릴게요..!

본문

팁자료실에 있는 외부이미지 저장할수 있는 소스인데요..!

(출처, untitle님)의 자료구요..!

기존에 타홈페이지에서 사진을 잘 복사 붙여넣기 했었는데 ㅠㅠ

 

한사이트에서 될때있고 안될때가 있는데요..!

 

혹시 아래 코드에서 어디쪽을 수정해야하는지 알수있을까요..

제가 초보라 자세히좀 부탁드릴게요..

 


<?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

답변을 작성하시기 전에 로그인 해주세요.
전체 25
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT