[제나플러스] 파일 업로드시 이미지 자동 리사이즈 하기 > 팁앤테크

본문 바로가기

사이트 내 전체검색

뒤로가기 팁앤테크

[제나플러스] 파일 업로드시 이미지 자동 리사이즈 하기

본문

write_update.skin.php

**********************

// 이미지 리사이즈
$data_path = $g4[path]."/data/file/$bo_table";

$sql2=" select * from $g4[board_file_table] where  bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no asc";
$results2 = sql_query($sql2);
for ($d=0; $row2=sql_fetch_array($results2); $d++)  {

if ($_FILES[bf_file][name][$d])
{
$file = $data_path .'/'. $row2[bf_file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file))
{
$size = getimagesize($file);
if ($size[2] == 1)
$src = imagecreatefromgif($file);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file);
else if ($size[2] == 3)
$src = imagecreatefrompng($file);
else
break;

$rate = $board[bo_image_width] / $size[0]; // 리사이즈를 원치않으면 여기서부터~~~
$height = (int)($size[1] * $rate);

if ($size[0] > $board[bo_image_width]){

@unlink($data_path.'/'.$row2[bf_file]);
$dst = imagecreatetruecolor($board[bo_image_width], $height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $board[bo_image_width], $height, $size[0], $size[1]);
imagejpeg($dst, $data_path.'/'.$row2[bf_file], 100); //혹 업로드 이미지 깨지면 여긴 주석처리하시고 바로 아래 껄 이용하세요..
// imagepng($dst, $data_path.'/'.$row2[bf_file], 100); //주석 해제
chmod($data_path.'/'.$row2[bf_file], 0606);

$temp = getimagesize(addslashes($file));
$filesize = filesize($file);

$sql = " update $g4[board_file_table]
            set bf_filesize = '{$filesize}',
                bf_width = '{$temp[0]}',
                bf_height = '{$temp[1]}'
          where bo_table = '$bo_table'
            and wr_id = '$wr_id'
            and bf_no = '$d' ";
sql_query($sql);
 
} // 리사이즈를 원치않으면 여기까지 삭제 & 주석처리하면 됨.
}
}
}
추천0

댓글목록 0

등록된 댓글이 없습니다.

전체 285건 1 페이지
게시물 검색
Copyright (c) 株式会社YHPLUS. All rights reserved.

사이트 정보

株式会社YHPLUS / 대표 : ZERO
〒171-0014 東京都豊島区池袋2-41-5 アーバン154 8F
050-5539-7787
오픈카카오톡 (YHPLUS) :
https://open.kakao.com/o/slfDj15d

PC 버전으로 보기