외부 이미지 다운로드 가져오는 함수

· 4년 전 · 2642

    function getdown_img($urlimage, $wr_id){

$save_image_file = "/home/xxxx/public_html/upload/xxxxx/".$wr_id;  //저장할 디렉토리    
$save_image_file2 = "../upload/xxxx/".$wr_id;  //저장할 디렉토리    

$url= "https://xxxxxx.com/"; // 가져올 외부 이미지

        $imagename_url_tmp1 = explode('" alt=',$urlimage);
        $imagename_url_tmp2 = explode('<img src="',$imagename_url_tmp1[0]);
        $imagename_url = $imagename_url_tmp2[1];

        $tmptime = date('YmdHis').(microtime(true) * 10000); //시간
        $imagename_tmp = basename($urlimage);
        $imagename_tmp2 = explode('" alt=',$imagename_tmp);
        $imagename_tmp3 = explode('<img src="',$imagename_tmp2[0]);
        //$imagename = $imagename_tmp2[0];
        $imagename = $imagename_url;

        if(preg_match("/\.(gif|jpg|jpeg|png)$/i", $imagename)) {  //이지지 확장자 체크


            $tmptime = date('YmdHis').(microtime(true) * 10000); //시간
            $save_file_name = $wr_id."-".$i."-".$tmptime;

            @mkdir($save_image_file, '757'); // 디렉토리 만들기
            @chmod($save_image_file, '757'); // 퍼미션 설정
 
            $filepath[0] = $save_image_file."/".$save_file_name.".jpg";
            copy($imagename, $filepath[0]);  ///이미지 url이 정확해야한다.
            $filepath[1] = $save_image_file2."/".$save_file_name.".jpg";

            $filepath = $filepath[1];
        
  } else {
       //echo 'error .';
  }
  return $filepath;

}

 

 

외부 이미지를 사용할 서버로 가져오는 함수입니다.

$save_image_file2 = "../upload/xxxx/".$wr_id;  //저장할 디렉토리    

위와같이 디렉토리 생성하고 /wr_id값을 붙여서 해당디렉토리에 이미지를 저장하게 됩니다.

 

 

 

|
댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

+
제목 글쓴이 날짜 조회
4년 전 조회 8,337
4년 전 조회 3,753
4년 전 조회 4,132
4년 전 조회 2,973
4년 전 조회 3,612
4년 전 조회 3,008
4년 전 조회 3,485
4년 전 조회 3,214
4년 전 조회 2,724
4년 전 조회 3,663
4년 전 조회 3,696
4년 전 조회 2,835
4년 전 조회 4,291
4년 전 조회 3,310
4년 전 조회 2,643
4년 전 조회 3,424
4년 전 조회 3,112
4년 전 조회 3,616
4년 전 조회 3,705
4년 전 조회 3,157
4년 전 조회 4,153
4년 전 조회 4,510
4년 전 조회 8,007
4년 전 조회 3,847
4년 전 조회 2,889
4년 전 조회 4,022
4년 전 조회 4,735
4년 전 조회 1.2만
4년 전 조회 2,726
4년 전 조회 3,409