팁자료실에 untitle 님께서 올려주신 소중한 자료입니다
외부이미지 자동 저장할수 있는 write_update.skin.php 파일인데요..!
홈페이지 에디터상에 복사+ 붙여넣기를 하였을경우
한홈페이지의 이미지가 외부이미지로 잘불러와줘서 저장이 되었다가
어떨때는 다시 오류가 날때가 있는데요..! 혹시 파일상에 어디를 조금 수정해야 할까요..!
오류가 날때는 이미지 번호? 이름과 .jpg로 나오고 있는데요..!
아래 코드 첨부할게요..!
<?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); } } ?>
답변 1개 / 댓글 1개
12번줄에 이미지 파일을 binary 형식으로 읽어와서 $data 에 넣네요. $data 체크 하시구요. 이걸로 체크가 안될경우
23~25번줄에 $out_path가 읽어온걸 저장한 파일인데요.
$info = @getimagesize($out_path);if( $info[2]==2 || $info[2]==3 || $info[2]==4 ) {return $change_filename;} else {return false;}
아래쪽도 save_remote_image 바로 쓰지 마시고 $temp = save_remote_image.... 이런식으로 한다음에 $temp 값 확인하고 처리
http://php.net/manual/kr/function.getimagesize.php
답변에 대한 댓글 1개
답변을 작성하려면 로그인이 필요합니다.
근대 제가 완전 초보(입문)자라서요...!
아무리봐도 어디서부터 해야할지 모르겠는데요 ㅠㅠ
혹시 자세히좀 알려주실수 있을까
도움좀 요청할게요 ㅠㅠ