초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
This commit is contained in:
179
php/common.php
Normal file
179
php/common.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?
|
||||
class Image {
|
||||
var $file;
|
||||
var $image_width;
|
||||
var $image_height;
|
||||
var $width;
|
||||
var $height;
|
||||
var $ext;
|
||||
var $types = array('','gif','jpeg','png','swf');
|
||||
var $quality = 70;
|
||||
var $top = 0;
|
||||
var $left = 0;
|
||||
var $crop = false;
|
||||
var $type;
|
||||
var $rotation_angle;
|
||||
var $dir;
|
||||
var $name;
|
||||
|
||||
function __construct($name='') {
|
||||
$this->file = $name;
|
||||
$info = getimagesize($name);
|
||||
$this->image_width = $info[0];
|
||||
$this->image_height = $info[1];
|
||||
$this->type = $this->types[$info[2]];
|
||||
$info = pathinfo($name);
|
||||
$this->dir = $info['dirname'];
|
||||
$this->name = str_replace('.'.$info['extension'], '', $info['basename']);
|
||||
$this->ext = $info['extension'];
|
||||
}
|
||||
|
||||
function dir($dir='') {
|
||||
if(!$dir) return $this->dir;
|
||||
$this->dir = $dir;
|
||||
}
|
||||
|
||||
function name($name='') {
|
||||
if(!$name) return $this->name;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
function width($width='') {
|
||||
$this->width = $width;
|
||||
}
|
||||
|
||||
function height($height='') {
|
||||
$this->height = $height;
|
||||
}
|
||||
|
||||
function resize($percentage=50) {
|
||||
if($this->crop) {
|
||||
$this->crop = false;
|
||||
$this->width = round($this->width*($percentage/100));
|
||||
$this->height = round($this->height*($percentage/100));
|
||||
$this->image_width = round($this->width/($percentage/100));
|
||||
$this->image_height = round($this->height/($percentage/100));
|
||||
} else {
|
||||
$this->width = round($this->image_width*($percentage/100));
|
||||
$this->height = round($this->image_height*($percentage/100));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function crop($top=0, $left=0) {
|
||||
$this->crop = true;
|
||||
$this->top = $top;
|
||||
$this->left = $left;
|
||||
}
|
||||
|
||||
function quality($quality=70) {
|
||||
$this->quality = $quality;
|
||||
}
|
||||
|
||||
function rotate($angle) {
|
||||
$this->rotation_angle = $angle;
|
||||
}
|
||||
|
||||
function show() {
|
||||
$this->save(true);
|
||||
}
|
||||
|
||||
function save($show=false) {
|
||||
|
||||
if($show) @header('Content-Type: image/'.$this->type);
|
||||
|
||||
if(!$this->width && !$this->height) {
|
||||
$this->width = $this->image_width;
|
||||
$this->height = $this->image_height;
|
||||
} elseif (is_numeric($this->width) && empty($this->height)) {
|
||||
$this->height = round($this->width/($this->image_width/$this->image_height));
|
||||
} elseif (is_numeric($this->height) && empty($this->width)) {
|
||||
$this->width = round($this->height/($this->image_height/$this->image_width));
|
||||
} else {
|
||||
if($this->width<=$this->height) {
|
||||
$height = round($this->width/($this->image_width/$this->image_height));
|
||||
if($height!=$this->height) {
|
||||
$percentage = ($this->image_height*100)/$height;
|
||||
$this->image_height = round($this->height*($percentage/100));
|
||||
}
|
||||
} else {
|
||||
$width = round($this->height/($this->image_height/$this->image_width));
|
||||
if($width!=$this->width) {
|
||||
$percentage = ($this->image_width*100)/$width;
|
||||
$this->image_width = round($this->width*($percentage/100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($this->crop) {
|
||||
$this->image_width = $this->width;
|
||||
$this->image_height = $this->height;
|
||||
}
|
||||
|
||||
if($this->type=='jpeg') $image = imagecreatefromjpeg($this->file);
|
||||
if($this->type=='png') $image = imagecreatefrompng($this->file);
|
||||
if($this->type=='gif') $image = imagecreatefromgif($this->file);
|
||||
|
||||
$new_image = imagecreatetruecolor($this->width, $this->height);
|
||||
imagecopyresampled($new_image, $image, 0, 0, $this->top, $this->left, $this->width, $this->height, $this->image_width, $this->image_height);
|
||||
|
||||
// Apply rotation if specified
|
||||
if(isset($this->rotation_angle) && $this->rotation_angle != 0) {
|
||||
$new_image = imagerotate($new_image, $this->rotation_angle, 0);
|
||||
}
|
||||
|
||||
$name = $show ? null: $this->dir.DIRECTORY_SEPARATOR.$this->name.'.'.$this->ext;
|
||||
|
||||
if($this->type=='jpeg') imagejpeg($new_image, $name, $this->quality);
|
||||
if($this->type=='png') imagepng($new_image, $name);
|
||||
if($this->type=='gif') imagegif($new_image, $name);
|
||||
|
||||
imagedestroy($image);
|
||||
imagedestroy($new_image);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// // 파일 압축 메소드 수정
|
||||
function compress_image($source, $destination, $quality) {
|
||||
$info = getimagesize($source);
|
||||
|
||||
if ($info['mime'] == 'image/jpeg') {
|
||||
$image = imagecreatefromjpeg($source);
|
||||
} elseif ($info['mime'] == 'image/gif') {
|
||||
$image = imagecreatefromgif($source);
|
||||
} elseif ($info['mime'] == 'image/png') {
|
||||
$image = imagecreatefrompng($source);
|
||||
} elseif ($info['mime'] == 'image/x-ms-bmp') {
|
||||
$image = imagecreatefrombmp($source);
|
||||
} else {
|
||||
return false; // 지원하지 않는 파일 형식
|
||||
}
|
||||
|
||||
// 압축된 파일 저장
|
||||
imagejpeg($image, $destination, $quality);
|
||||
|
||||
// 크기 조정 (최대 800px)
|
||||
list($width, $height) = getimagesize($destination);
|
||||
if ($width > 800 || $height > 800) {
|
||||
$rate = $width / $height;
|
||||
|
||||
if ($width > $height) {
|
||||
$new_width = 800;
|
||||
$new_height = 800 / $rate;
|
||||
} else {
|
||||
$new_width = 800 * $rate;
|
||||
$new_height = 800;
|
||||
}
|
||||
|
||||
// `Image` 클래스를 사용해 크기 조정
|
||||
$imageObj = new Image($destination);
|
||||
$imageObj->width($new_width);
|
||||
$imageObj->height($new_height);
|
||||
$imageObj->save(false); // 파일을 다시 저장
|
||||
}
|
||||
|
||||
return $destination; // 최종 파일 경로 반환
|
||||
}
|
||||
?>
|
||||
29
php/gap_time.php
Normal file
29
php/gap_time.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// 두 날짜의 차이를 구한다.
|
||||
function gap_time($start_date, $end_date) {
|
||||
|
||||
// $end_date = strtotime("2021-12-10 23:50:00"); // 끝나는 시간
|
||||
// $today = strtotime(date("Ymd H:i:s")); //현재시간
|
||||
|
||||
$start_time = strtotime($start_date);
|
||||
$end_time = strtotime($end_date);
|
||||
|
||||
$diff = $end_time - $start_time;
|
||||
|
||||
$hours = floor($diff/3600);
|
||||
|
||||
$diff = $diff-($hours*3600);
|
||||
|
||||
$min = floor($diff/60);
|
||||
|
||||
$sec = $diff - ($min*60);
|
||||
|
||||
// return $hours.":".$min.":".$sec;
|
||||
return sprintf("%02d:%02d:%02d", $hours, $min, $sec);
|
||||
|
||||
}
|
||||
|
||||
print gap_time("2021-12-10 18:00:00","2021-12-10 23:50:00");
|
||||
|
||||
|
||||
?>
|
||||
82
php/pathinfo.php
Normal file
82
php/pathinfo.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<input type='file' id='fileInput'>
|
||||
<input type='button' value='파일명 표시하기' onclick='fileCheck()'>
|
||||
<input type="text" id=fileInput name=fileInput >
|
||||
|
||||
<?php
|
||||
// $file_url = 'http://webisfree.com/cdn/images/test.jpg';
|
||||
|
||||
echo pathinfo($file_url, PATHINFO_DIRNAME) . "<br>" ; // 상위, 루트 경로를 반환
|
||||
echo pathinfo($file_url, PATHINFO_BASENAME) . "<br>" ; // 파일명과 확장자 모두 출력
|
||||
echo pathinfo($file_url, PATHINFO_EXTENSION) . "<br>" ; // 확장자만 출력
|
||||
echo pathinfo($file_url, PATHINFO_FILENAME) . "<br>" ; // 이름만 출력
|
||||
$url_path = pathinfo($file_url, PATHINFO_DIRNAME);
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<script type='text/javascript'>
|
||||
//1MB(메가바이트)는 1024KB(킬로바이트)
|
||||
var maxSize = 2048;
|
||||
|
||||
function fileCheck() {
|
||||
//input file 태그.
|
||||
var file = document.getElementById('fileInput');
|
||||
//파일 경로.
|
||||
var filePath = file.value;
|
||||
//전체경로를 \ 나눔.
|
||||
var filePathSplit = filePath.split('\\');
|
||||
//전체경로를 \로 나눈 길이.
|
||||
var filePathLength = filePathSplit.length;
|
||||
//마지막 경로를 .으로 나눔.
|
||||
var fileNameSplit = filePathSplit[filePathLength-1].split('.');
|
||||
//파일명 : .으로 나눈 앞부분
|
||||
var fileName = fileNameSplit[0];
|
||||
//파일 확장자 : .으로 나눈 뒷부분
|
||||
var fileExt = fileNameSplit[1];
|
||||
//파일 크기
|
||||
var fileSize = file.files[0].size;
|
||||
|
||||
console.log('파일 경로 : ' + filePath);
|
||||
console.log('파일명 : ' + fileName);
|
||||
console.log('파일 확장자 : ' + fileExt);
|
||||
console.log('파일 크기 : ' + fileSize);
|
||||
|
||||
var a = document.getElementById("fileInput").value
|
||||
|
||||
a.innerHTML= filePath;
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
function imageChange() {
|
||||
var input = document.memberform.file;
|
||||
var fReader = new FileReader();
|
||||
fReader.readAsDataURL(input.files[0]);
|
||||
console.log(input.files[0]);
|
||||
fReader.onloadend = function(event){
|
||||
document.memberform.image.src = event.target.result;
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<body>
|
||||
<form id=memberform name=memberform>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="2" style="width: 60%"><img
|
||||
src="image/touchtouch.PNG" name=image width="150" height="150" onchange=""></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="2" style="width: 60%"><input type="file"
|
||||
name=file accept=".gif, .jpg, .png" onchange="imageChange()"></td>
|
||||
<!-- accept=".gif, .jpg, .png" 의 확장자만 허용한다 -->
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
Reference in New Issue
Block a user