컨텐츠 내용중 첫번째 IMG주소 뽑아내기
2018. 2. 27. 11:54
GD
2018. 2. 27. 11:49
## 기본 GD처리
$file_name_arr = explode(".", $_FILES['name']); $extention = strtolower($file_name_arr[count($file_name_arr)-1]); $file_name = time()."_".rand(9999,9999999).".".$extention; // 파일명 임의생성 $output_image = $files_data['tmp_name']; $upload_file_path = $_FILES['tmp_name']; $upload_file_type = mime_content_type($upload_file_path); //타입별로 로드시킴 switch($upload_file_type) { case "image/png": $im = imagecreatefrompng($upload_file_path); break; case "image/jpg": case "image/jpeg": $im = imagecreatefromjpeg($upload_file_path); break; case "image/gif": $im = imagecreatefromgif($upload_file_path); break; } if($im) { $output_image = _IMAGE_DIR.$folder_dir."/".$file_name; // 이미지 저장 위치 $imginfo = getimagesize($upload_file_path); imagecopyresampled($im, $im, 0, 0, 0, 0, 0, 0, $imginfo[0], $imginfo[1]); //이미지생성부분 //imagejpeg($im, $destpath, 100); switch($extention){ case 'gif': imagegif($im,$output_image); break; case 'png': imagepng($im,$output_image); break; case 'jpg': case 'jpeg': imagejpeg($im,$output_image, 100);break; //JPG 이미지로 표출됨 default : $rs['result'] = false; $rs['msg'] = '이미지 처리 실패'; return $rs; } ImageDestroy($im); //메모리 해제 }
'프로그래밍 > php' 카테고리의 다른 글
PHP Simple HTML DOM Parser (0) | 2018.02.27 |
---|---|
정규식 예제 (0) | 2018.02.27 |
컨텐츠 내용중 첫번째 IMG주소 뽑아내기 (0) | 2018.02.27 |
captcha (0) | 2018.02.27 |
날짜 or 시간 (0) | 2018.02.27 |
captcha
2018. 2. 27. 11:24
PHP simple captcha
PHP용 심플 captcha
https://github.com/claviska/simple-php-captcha
thx to Cory LaViska.
사용법소개
데모 소스
위의 라이브러리를 가지고 직접 데모를 만들어 보았다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | <? session_start(); include ( "simple-php-captcha.php" ); $PREV_Captcha = $_SESSION [ 'captcha' ][ 'code' ]; $POST_Captcha = $_POST [ 'captcha' ]; if ( ! empty ( $PREV_Captcha ) && ! empty ( $POST_Captcha ) ) { if ( strcasecmp ( $PREV_Captcha , $POST_Captcha ) != 0 ) { echo "<script>alert('이미지에 출력된 글자와 다릅니다.');</script>" ; } else { echo "<script>alert('정상');</script>" ; } } //end if $_SESSION [ 'captcha' ] = simple_php_captcha(); ?> <!DOCTYPE html> <html lang= "en" > <head> <!-- meta --> <meta name= "Author" content= "serpiko@hanmail.net" /> <meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" /> <meta charset= "utf-8" > <meta http-equiv= "X-UA-Compatible" content= "IE=edge, chrome=1" /> <meta name= "viewport" content= "width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" /> <meta name= "format-detection" content= "telephone=no" /> <!-- link --> <link rel= "stylesheet" type= "text/css" href= "" /> <!-- script --> <title>Document</title> <style> * { box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; } </style> </head> <body> <div id= "wrap" > <form method= 'post' action= '<?=$PHP_SELF?>' > PREV_Captcha : <input type= 'text' size= '100' value= '<?=$PREV_Captcha?>' /> <br /> POST_Captcha : <input type= 'text' name= '' size= '100' value= '<?=$POST_Captcha?>' /> <br /><br /> 할당된 캡챠<br /> <img src= "<?=$_SESSION['captcha']['image_src']?>" style= 'width:100px;border:1px solid blue;border-radius:7px;' /><br /><br /> 사용자 캡챠 입력<br /> captcha : <input type= 'text' size= '100' name= 'captcha' value= "" /> <br /> <button type= 'submit' >확인</button> </form> </div> </body> </html> |
데모 보기
출처: http://serpiko.tistory.com/589 [삽SAP(Study And Programming) 질 블로그. by허정진]
'프로그래밍 > php' 카테고리의 다른 글
PHP Simple HTML DOM Parser (0) | 2018.02.27 |
---|---|
정규식 예제 (0) | 2018.02.27 |
컨텐츠 내용중 첫번째 IMG주소 뽑아내기 (0) | 2018.02.27 |
GD (0) | 2018.02.27 |
날짜 or 시간 (0) | 2018.02.27 |