<?php
// 이미지 src 추출
preg_match_all('/<img[^>]*src=["\']?([^>"\']+)["\']?[^>]*>/i', $input_text, $img_no);
$img_src = $img_no[1][0] ?? '';
if ($img_src) {
// 파일명 추출
$filename = basename(parse_url($img_src, PHP_URL_PATH)); // 쿼리스트링 제거
// 저장 경로 설정
$source_path = $target_path = G5_DATA_PATH . '/file/' . $bo_table;
$file_download = $target_path . '/' . $filename;
// 디렉토리 없으면 생성
if (!is_dir($target_path)) {
mkdir($target_path, 0755, true);
}
// 파일이 없으면 복사 시도
if (!file_exists($file_download)) {
// 외부 이미지 다운로드
$image_data = @file_get_contents($img_src);
if ($image_data !== false) {
file_put_contents($file_download, $image_data);
} else {
// 실패 시 로그 또는 대체 이미지 처리
error_log("이미지 다운로드 실패: $img_src");
}
}
// 썸네일 생성
if (file_exists($file_download)) {
$thumb_src = thumbnail($filename, $source_path, $target_path, "50", "35", false, true);
$img_src = G5_DATA_URL . '/file/' . $bo_table . '/' . $thumb_src;
}
}
?>
'PHP Tip' 카테고리의 다른 글
| 오버레이가 있는 반응형 이미지 갤러리(그누보드) (0) | 2025.12.17 |
|---|---|
| 쿠키 값으로 방문자 횟수 표시 (1) | 2025.12.16 |
| 임대 서버 환경에서 트래픽을 줄이고 사이트 성능을 최적화하려면(그누보드) (0) | 2025.12.16 |
| Apache의 에서 User-Agent 기반으로 특정 봇을 차단하는 방식입니다. (0) | 2025.12.14 |
| sitemap.xml 자동 만들기 (0) | 2025.12.14 |