Server IP : 119.59.102.212 / Your IP : 18.218.54.80 Web Server : Apache/2 System : Linux narin 2.6.32-042stab142.1 #1 SMP Tue Jan 28 23:44:17 MSK 2020 x86_64 User : yangkam ( 1022) PHP Version : 5.6.40 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/yangkam/domains/yangkam.go.th/private_html/coremain/ |
Upload File : |
<?php // fieldset function fieldset_top($name_top){ echo "<fieldset><legend align=left><font color='$datatm[color1]'>$name_top </font></legend> "; } function fieldset_down(){ echo "</fieldset>"; } // ########### ไม่มีสิทธิ์ในหน้านี้ ############ function permission_fail(){ bar_header("คุณไมีมีสิทธิ์ในหน้านี้"); // Bar_Header fieldset_top("คุณไมีมีสิทธิ์ในหน้านี้"); print "<font color='ff0000'><center><b>การกระทำของคุณล่อแหลมต่อความปลอดภัยของระบบ</b></font>"; print "<br><br><a href='index.php'><font color='ff0000'>คลิกที่นี่</font></a> เพื่อกลับสู่หน้าหลัก</center>"; $widthsl='190'; fieldset_down(); include("footer.php"); exit; } // ########### ไม่มีสิทธิ์ใน Module นี้ ########## function fieldset_no_module(){ bar_header("หน่วยงานของท่านไม่มีสิทธิ์ในหน้านี้"); // Bar_Header fieldset_top("หน่วยงานของท่านไม่มีสิทธิ์ในหน้านี้"); print "<font color='ff0000'><center><b>ขออภัย หน่วยงานของท่านไม่มีสิทธิ์ในหน้านี้ </b></font>"; print "<br><br><font color='000000'><center><b>หากท่านต้องการใช้ Module ส่วนนี้ กรุณาติดต่อ <br><br>opstech@windowslive.com : <a href='http://www.opstech.co.th' target=blank>http://www.opstech.co.th</b></font>"; print "<br><br><a href='index.php'><font color='ff0000'>คลิกที่นี่</font></a> เพื่อกลับสู่หน้าหลัก</center>"; $widthsl='180'; fieldset_down(); include("footer.php"); exit; } // ข้อมูลได้ถูกเพิ่มแล้ว function msg_insert_data(){ echo "<center><br><br>ข้อมูลได้ถูกเพิ่มแล้ว<br><br><br></center>"; } // ข้อมูลได้ถูกแก้ไขแล้ว function msg_update_data(){ echo "<center><br><br>ข้อมูลได้ถูกแก้ไขแล้ว<br><br><br></center>"; } // ข้อมูลได้ถูกลบแล้ว function msg_delete_data(){ echo "<center><br><br>ข้อมูลได้ถูกลบแล้ว<br><br><br></center>"; } // Refresh หน้าจอ function refresh_data($index_link,$time){ if($time=="") $time=2; echo"<meta http-equiv='refresh' content='$time; url=$index_link'>"; } // อธิบายขนาดของรูปว่าเท่าไหร่ถึงจะดี function detail_pic(){ echo" <img src='coremain/images/bu.gif' border='0' title='รูปควรมีขนาดประมาณ 400*300 Pixel' onmouseover=this.style.cursor='hand'>"; } // อธิบายชนิดของไฟล์ว่าเป็นอย่างไร function detail_file(){ echo" <img src='coremain/images/bu.gif' border='0' title='ไฟล์ต้องไม่ใช่ .php หรือ .asp หรือ .exe' onmouseover=this.style.cursor='hand'>"; } // #### Create Text Editor #### /*function text_editor($width,$height,$values,$msg){ echo"<tr height='40'>"; echo" <td><div align='left'><img src='coremain/images/marker.gif'> $msg</div></td> "; echo" <td><div align='left'></div>"; $oFCKeditor = new FCKeditor('evar') ; $oFCKeditor->BasePath = 'coremain/editor/'; $oFCKeditor->Value = $values; $oFCKeditor->Width = $width; $oFCKeditor->Height = $height; $oFCKeditor->Create() ; echo" </td> "; echo"</tr>"; }*/ //### File Upload ### /*function file_upload($msg, $id, $desc, $fold, $form, $input, $maxFileCount = 0){ echo "<tr height='40'>"; echo "<td><div align='left'><img src='coremain/images/marker.gif'> $msg</div></td> "; echo "<td><div id='fileuploader'>เลือกไฟล์...</div><div id='txt_error'></div></td>"; echo "</tr>"; echo "<script> var $id = $('#fileuploader').uploadFile({ autoSubmit:false, url: 'coremain/file_upload.php', fileName: 'fname', dragDropStr: '', uploadStr: 'เลือกไฟล์...', cancelStr: 'ยกเลิก', extErrorStr: 'ไม่อนุญาตให้อัพโหลด ! กรุณาตรวจสอบประเภทไฟล์ ', dragDropStr: '<span>$desc</span>', formData: {'path_dir': '$fold'}, returnType: 'json', allowedTypes: 'jpg, png, gif, doc, docx, xls, xlsx, pdf', afterUploadAll: function(obj){ var num = 0; $.each(obj.responses, function(i, v){ if(v != ''){ $('#$form').append('<input type=\"hidden\" name=\"$input'+ (i + 1) +'\" value=\"'+ v +'\" />'); ++num; } }); if(num == 0){ $('#txt_error').html('<span style=\'color: red;\'>$desc</span>'); } }, onSuccess: function(){ alert('123'); $('#$form').submit(); alert('456'); }"; if($maxFileCount > 0){ echo ",maxFileCount: $maxFileCount ,maxFileCountErrorStr: 'ไม่สำเร็จ ! เนื่องจากสามารถอัพโหลดได้มากที่สุดคือ '"; } echo " }); </script>"; }*/ //#### ปุ่มเพิ่มข้อมูล #### function text_button_insert($col = 2){ echo "<tr height='40'>"; echo "<td colspan='$col' align='center'> "; echo '<button type="submit" name="submit" class="ui-button ui-widget ui-corner-all btn-edit" style="padding: 5px 10px;">เพิ่มข้อมูล</button>'; echo "</td> "; echo "</tr>"; // echo" <input type='submit' name='Submit' value='เพิ่มข้อมูล' onmouseover=this.style.cursor='hand'>"; } function text_button_mail(){ echo" <input type='submit' name='Submit' value='ส่งอีเมล์' onmouseover=this.style.cursor='hand'>"; } //#### ปุ่มแก้ไขข้อมูล #### function text_button_update($col = 2, $upload_id = ''){ echo "<tr height='40'>"; echo " <td colspan='$col' align='center'> "; echo '<button type="submit" name="submit" class="ui-button ui-widget ui-corner-all btn-edit" style="padding: 5px 10px;">แก้ไขข้อมูล</button>'; echo " </td> "; echo " </tr>"; } // ################ ตรวจสอบวันที่ประกาศ กับ วันสิ้นสุดประกาศ ## function check_date($date_post,$date_line){ if($date_post>$date_line){ echo "<br><br><center>สิ้นสุดวันประกาศ ไม่ถูกต้อง !<br><br>"; echo"<a href='javascript:history.back()'><font color='ff0000'>[แก้ไขใหม่]</font></center></a><br><br>"; include('footer.php'); exit; } } // มีไฟล์อยู่แล้วแต่เอาออก function check_pic_out($tables,$fields,$id_del,$paths,$id_field){ $sql="select $fields from $tables where $id_field='$id_del'"; $result=mysql_query($sql); $data=mysql_fetch_row($result); if($data[0]!="") { unlink("$paths/$data[0]"); } } // ################ ตรวจสอบชนิดของไฟล์ ################ function check_pic($userfilename, $numberfile) { $arr = explode('.', $userfilename); $strings = '.'.end($arr);#$strings = substr($userfilename, -4); if ($strings != ".gif" && $strings != ".jpg" && $strings != ".GIF" && $strings != ".JPG" && $strings != ".png" && $strings != ".PNG") { echo"<center><br>ไฟล์ที่ $numberfile ชนิดไฟล์ไม่ถูกต้อง <br>ไฟล์ต้องมีนามสกุลเป็น .gif หรือ .jpg หรือ .png เท่านั้น <br>และขนาดไฟล์ต้องไม่เกิน 2 Mb.<br><br>"; echo"<a href='javascript:history.back()'><font color='ff0000'>[แก้ไขใหม่]</font></center></a><br><br>"; // include('footer.php'); exit; } } /*// ################## ชนิดของไฟล์เสี่ยงต่อความปลอดภัยของระบบ ############### function check_file($userfilename){ $arr = explode('.', $userfilename); $strings = '.'.end($arr); if($strings == '.php' || $strings == '.asp'){ return "<center><br>ไม่อนุญาตให้ Upload ไฟล์ชนิดนี้ <br>เนื่องจากชนิดไฟล์เสี่ยงต่อความเสียหายของระบบ <br>และขนาดไฟล์ต้องไม่เกิน 2 Mb.<br><br>"; //exit; }else{ return 'OK'; } // $strings=substr($userfilename,-4); // if($strings==".php" or $strings==".asp"){ // echo"<center><br>ไม่อนุญาตให้ Upload ไฟล์ชนิดนี้ <br>เนื่องจากชนิดไฟล์เสี่ยงต่อความเสียหายของระบบ <br>และขนาดไฟล์ต้องไม่เกิน 2 Mb.<br><br>"; // echo"<a href='javascript:history.back()'><font color='ff0000'>[แก้ไขใหม่]</font></center></a><br><br>"; // include('footer.php'); // exit; // } } // ############## สร้างชื่อไฟล์ใหม่ function create_filename($userfilename){ // //$strings=substr($userfilename,-4); // $arr = explode('.', $userfilename); // $strings = '.'.end($arr); $strings = get_file_type($userfilename); $str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"; $pic1 = substr(str_shuffle($str), 0, 12); $name1="$pic1$strings"; return ($name1); } */ // ############## Upload File ขึ้น Server /*function upload_file_to_server($dlink, $userfile) { $temp_name = $userfile['tmp_name']; if (is_uploaded_file($userfile['tmp_name'])) { if (!move_uploaded_file($temp_name, $dlink)) { } } }*/ // ลบไฟล์เก่าทิ้งในกรณีที่จะ Upload ไฟล์ใหม่ทับ function delete_filename($tables,$fields,$id_del,$paths,$id_filed){ $sql="select $fields from $tables where $id_filed='$id_del'"; $result=mysql_query($sql); $data=mysql_fetch_row($result); if($data[0]!="" && file_exists("$paths/$data[0]")) { @unlink("$paths/$data[0]"); } } // Check_Picture Width function check_pic_width($width, $name1) { if ($width > 160) { unlink("$_SESSION[web_name]/mainfile/$name1"); echo "<center><br><br>ไฟล์มีขนาดความกว้างเกิน 200 Pixel ซึ่งมากเกินไป<br><br></center>"; echo"<a href='javascript:history.back()'><center><font color='ff0000'>[แก้ไขใหม่]</font></center></a><br><br>"; include('footer.php'); exit; } } // Check_Picture Height function check_pic_height($height, $name1) { if ($height > 150) { unlink("$_SESSION[web_name]/mainfile/$name1"); echo "<center><br><br>ไฟล์มีขนาดความสูงเกิน 150 Pixel ซึ่งมากเกินไป<br><br></center>"; echo"<a href='javascript:history.back()'><center><font color='ff0000'>[แก้ไขใหม่]</font></center></a><br><br>"; include('footer.php'); exit; } } // Check_User_Permission // ################ ตรวจสอบวันที่ประกาศ กับ วันสิ้นสุดประกาศ ## function check_user_permission($user) { if ($user != "admin") { echo "<br><br><center><font color='ff0000'><b>คุณไม่มีสิทธิ์ใช้งานหน้านี้</b></font><br><br>"; include('footer.php'); exit; } } ################# KJ : for new version ############### function debuga($array){ if(is_array($array)){ echo '<hr/><pre align="left">'; print_r($array); echo '</pre><hr/>'; }else{ echo '<br/>====== This data is not Array ======<br/>'; } } function setArrayToAdd($array) { if (is_array($array)) { foreach ($array as $k => $v) { $_array[$v['name']] = (isset($v['value'])) ? trim($v['value']) : ''; } return $_array; } } function text_editor($width, $height, $title, $colspan = '2', $values = '', $name = 'evar'){ if($colspan > 0){ echo "<tr height='40'>"; echo "<td colspan='$colspan'> <img src='coremain/images/marker.gif'> <b>$title</b><br/>"; } echo " <textarea id='$name' name='$name'>$values</textarea>"; if($colspan > 0){ echo "</td>"; echo "</tr>"; } echo "<script> CKEDITOR.config.width = '100%'; CKEDITOR.config.height = $height; CKEDITOR.replace( '$name', { filebrowserBrowseUrl: 'coremain/ckeditor/filemanager/dialog.php?type=2&editor=ckeditor&fldr=', filebrowserImageBrowseUrl: 'coremain/ckeditor/filemanager/dialog.php?type=1&editor=ckeditor&fldr=', extraPlugins: 'youtube,iframe' }); CKEDITOR.config.allowedContent = true; </script>"; } //### File Upload ### function file_upload($upload_id, $fold, $form, $url, $option = array()){ #$option = array('title', 'description', 'text_error', 'colspan', 'file_type', 'max_file', 'multiple', 'prefix', 'thumb', 'extraHTML (array)'); $msg = isset($option['title']) ? $option['title'] : 'ไฟล์ประกอบ'; $desc = isset($option['description']) ? $option['description'] : ''; $txtError = isset($option['text_error']) ? $option['text_error'] : 'ไม่อนุญาตให้อัพโหลด ! กรุณาตรวจสอบประเภทไฟล์ '; $colspan = isset($option['colspan']) ? "colspan='$option[colspan]'" : ""; $_file_type = isset($option['file_type']) ? $option['file_type'] : ''; $allowed_types = $_file_type == 'image' ? 'jpg, png, gif' : 'jpg, png, gif, doc, docx, xls, xlsx, pdf'; $maxFileCount = isset($option['max_file']) ? $option['max_file'] : 0; $multiple = isset($option['multiple']) ? $option['multiple'] : 'true'; $prefix = isset($option['prefix']) ? ", 'prefix': '$option[prefix]'" : ''; $thumb = isset($option['thumb']) && $option['thumb'] == true ? ", 'thumb': 'thumb'" : ''; $extraHTML = isset($option['extraHTML']) ? 'fn' : ''; echo "<tr height='40' valign='top'>"; echo "<td><div align='left'><img src='coremain/images/marker.gif'> <b>$msg</b></div></td> "; echo "<td $colspan><div id='fileuploader'>เลือก...</div><div id='txt_error'></div></td>"; echo "</tr>"; echo "<script> var $upload_id = $('#fileuploader').uploadFile({ autoSubmit: false, url: 'coremain/file_upload.php', fileName: 'fname', dragDropStr: '', uploadStr: 'เลือกไฟล์...', cancelStr: 'ยกเลิก', extErrorStr: '$txtError', dragDropStr: '<span>$desc</span>', formData: {'path_dir': '$fold' $prefix $thumb}, returnType: 'json', sequential: true, sequentialCount: 1, uploadQueueOrder: 'bottom', multiple: $multiple, allowedTypes: '$allowed_types', afterUploadAll: function(obj){ var arrayData = $('#$form').serializeArray(); var txtArea = $('#$form').find('textarea'); if(txtArea.length > 0){ var row = {}; row.name = txtArea.attr('name'); row.value = CKEDITOR.instances[txtArea.attr('id')].getData(); arrayData.push(row); } $.ajax({ url: '$url', type: 'post', data: {fileData: obj.responses, formData: arrayData}, success: function(result){ var chk = result.substr(0, 1); if(chk == 0){ var txt = result.substr(0); alert(txt); return false; }else{ window.location.href = result; } } }); }"; if($_file_type == 'image'){ echo ',acceptFiles: "image/*"'; } if($maxFileCount > 0){ echo ",maxFileCount: $maxFileCount ,maxFileCountErrorStr: 'ไม่สำเร็จ ! เนื่องจากสามารถอัพโหลดได้มากที่สุดคือ '"; } if($extraHTML == 'fn'){ echo ",extraHTML: function(){ var html = '<div>';"; foreach($option['extraHTML'] as $ele){ if($ele['type'] == 'input'){ #array('type' => 'input', 'text' => 'คำอธิบายรูป', 'name' => 'explain', 'style' => 'width: 100%;') echo " html += '<b>$ele[text] : </b><input type=\"text\" name=\"$ele[name]\" style=\"$ele[style]\" /> <br/>';"; }else if($ele['type'] == 'select'){ #array('type' => 'select', 'text' => 'ตำแหน่ง', 'name' => 'position', 'style' => 'width: 100%;', 'option' => array('1' => 'กลาง', '2' => 'ซ้าย', '3' => 'ขวา') echo " html += '<b>$ele[text] : </b><select name=\"$ele[name]\" style=\"$ele[style]\">';"; foreach($ele['option'] as $value => $text){ echo " html += '<option value=\"$value\">$text</option>';"; } echo " html += '</select>';"; } } echo " html += '</div>'; return html; }"; } echo " }); </script>"; } //### ปุ่ม Upload เอกสาร/รูปภาพ ### # file_upload.$upload_id = text_button_upload.$upload_id function button_text($bt_text, $name = 'submit', $col = 2, $upload_id = '', $txt_validate = '', $allow_nofile_in_startUpload = 'false') { if ($col > 0) { echo "<tr height='40'>"; echo "<td colspan='$col' align='center'><br/>"; } $btType = $upload_id != '' ? 'button' : 'submit'; echo '<button type="' . $btType . '" name="' . $name . '" class="ui-button ui-widget ui-corner-all ui-state-focus '.$upload_id.'" id="'.$upload_id.'" style="padding: 5px 10px;">' . $bt_text . '</button>'; if ($col > 0) { echo "</td> "; echo "</tr>"; } if ($upload_id != '') { $chkType = explode('_', $upload_id); if($chkType[0] != 'btn'){ echo "<script> $('.$upload_id').click(function(){ $upload_id.startUpload('$txt_validate', $allow_nofile_in_startUpload); }); </script>"; } } } // ############## Upload File ขึ้น Server /*function upload_file_to_server($dlink, $file, $thumbPath = '', $width = '800', $height = '600') { $temp_name = $file['tmp_name']; if (is_uploaded_file($file['tmp_name'])) { if (!move_uploaded_file($temp_name, $dlink)) { }else{ createResizedImage($dlink, $thumbPath, $width, $height); } } }*/ function upload_file_to_server($_dlink, $file, $_thumbPath = '', $width = '800', $height = '600') { $arr = explode('/', $_dlink); $file_name = end($arr); $file_type = get_file_type($file_name); $filename = str_replace($file_type, '', $file_name); $imp_dlink = implode('/', $arr); $dlink = str_replace($file_name, '', $imp_dlink); $thumbPath = $_thumbPath != '' ? str_replace($file_name, '', $_thumbPath) : ''; include_once('module/class.upload.php'); $hup = new upload($file); //chmod($output_dir, 0755); if($hup->uploaded){ $hup->image_resize = true; $hup->image_y = $height; $hup->image_x = $width; $hup->image_ratio = true; $hup->jpeg_quality = 95; $hup->image_ratio_no_zoom_in = true; $hup->file_new_name_body = $filename; $hup->Process($dlink); if($hup->processed){ }else{ //echo 'failed'; } if($thumbPath != ''){ $hup->image_resize = true; $hup->image_y = 100; $hup->image_x = 150; $hup->image_ratio = true; $hup->jpeg_quality = 95; $hup->image_ratio_no_zoom_in = true; $hup->file_new_name_body = $filename; $hup->Process($thumbPath); if($hup->processed){ }else{ } } } } function createResizedImage($imagePath, $thumbPath, $newWidth, $newHeight){ #, $outExt) { $newPath = $imagePath; if ($newPath === '' || file_exists($imagePath) === false) { return null; } $type = @exif_imagetype($imagePath); if (in_array($type, [IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF]) === false) {//[IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_BMP, IMAGETYPE_WEBP] return null; } list($width, $height) = getimagesize($imagePath); // $outBool = in_array($outExt, ['jpg', 'jpeg', 'png', 'gif']);//, 'bmp', 'webp']); switch (true) { case $type === IMAGETYPE_JPEG: $image = imagecreatefromjpeg($imagePath); // if ($outBool === false) $outExt = 'jpg'; break; case $type === IMAGETYPE_PNG: $image = imagecreatefrompng($imagePath); // if ($outBool === false) $outExt = 'png'; break; case $type === IMAGETYPE_GIF: $image = imagecreatefromgif($imagePath); // if ($outBool === false) $outExt = 'gif'; break; // case $type === IMAGETYPE_BMP: // $image = imagecreatefrombmp($imagePath); //// if ($outBool === false) // $outExt = 'bmp'; // break; // case $type === IMAGETYPE_WEBP: // $image = imagecreatefromwebp($imagePath); //// if ($outBool === false) // $outExt = 'webp'; } ### KJ : cal width height auto by one ### // echo '==='.$width.'::'.$newWidth.'=='.$height.'::'.$newHeight.'==='; if($width > $newWidth || $height > $newHeight){ $calHeight = round($newWidth*$height/$width); // echo '++'.$calHeight.'::'.$newHeight.'++'; if($calHeight > $newHeight && $newHeight > 0){ $newWidth = round($newHeight*$newWidth/$calHeight); }else{ $newHeight = $calHeight; } ### ================ ### $newImage = imagecreatetruecolor($newWidth, $newHeight); //TRANSPARENT BACKGROUND $color = imagecolorallocatealpha($newImage, 0, 0, 0, 127); //fill transparent back imagefill($newImage, 0, 0, $color); imagesavealpha($newImage, true); //ROUTINE imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); // Rotate image on iOS $exif = @exif_read_data($imagePath, 'IFD0'); if (isset($exif['Orientation']) && isset($exif['Make']) && !empty($exif['Orientation']) && preg_match('/(apple|ios|iphone)/i', $exif['Make'])) { switch ($exif['Orientation']) { case 8: if ($width > $height) $newImage = imagerotate($newImage, 90, 0); break; case 3: $newImage = imagerotate($newImage, 180, 0); break; case 6: $newImage = imagerotate($newImage, -90, 0); break; } } switch (true) { case in_array($outExt, ['jpg', 'jpeg']) === true: $success = imagejpeg($newImage, $newPath); break; case $outExt === 'png': $success = imagepng($newImage, $newPath); break; case $outExt === 'gif': $success = imagegif($newImage, $newPath); break; // case $outExt === 'bmp': $success = imagebmp($newImage, $newPath); // break; // case $outExt === 'webp': $success = imagewebp($newImage, $newPath); } if ($success === false) { return null; } #N#return $newPath; } ### thumbnail ### if($thumbPath != ''){ $thumbWidth = 150; $thumbHeight = 100; if($width > 150 || $height > 100){ $calHeight = round($thumbWidth*$height/$width); if($calHeight > $thumbHeight){ $thumbWidth = round($thumbHeight*$thumbWidth/$calHeight); }else{ $thumbHeight = $calHeight; } ### ================ ### $thumbImage = imagecreatetruecolor($thumbWidth, $thumbHeight); //TRANSPARENT BACKGROUND $color = imagecolorallocatealpha($thumbImage, 0, 0, 0, 127); //fill transparent back imagefill($thumbImage, 0, 0, $color); imagesavealpha($thumbImage, true); //ROUTINE imagecopyresampled($thumbImage, $image, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $width, $height); // Rotate image on iOS $exif = @exif_read_data($imagePath, 'IFD0'); if (isset($exif['Orientation']) && isset($exif['Make']) && !empty($exif['Orientation']) && preg_match('/(apple|ios|iphone)/i', $exif['Make'])) { switch ($exif['Orientation']) { case 8: if ($width > $height) $thumbImage = imagerotate($thumbImage, 90, 0); break; case 3: $thumbImage = imagerotate($thumbImage, 180, 0); break; case 6: $thumbImage = imagerotate($thumbImage, -90, 0); break; } } switch (true) { case in_array($outExt, ['jpg', 'jpeg']) === true: $success = imagejpeg($thumbImage, $thumbPath); break; case $outExt === 'png': $success = imagepng($thumbImage, $thumbPath); break; case $outExt === 'gif': $success = imagegif($thumbImage, $thumbPath); break; } if ($success === false) { return null; } } } // return null; } function upload_file_to_server2($dlink, $file){ $temp_name = $file['tmp_name']; if (is_uploaded_file($file['tmp_name'])) { if (!move_uploaded_file($temp_name, $dlink)) { } } } /*function upload_file_to_server2($_dlink, $file, $_thumbPath = '', $width = '800', $height = '600') { $arr = explode('/', $_dlink); $file_name = end($arr); $file_type = get_file_type($file_name); $filename = str_replace($file_type, '', $file_name); $imp_dlink = implode('/', $arr); $dlink = str_replace($file_name, '', $imp_dlink); $thumbPath = $_thumbPath != '' ? str_replace($file_name, '', $_thumbPath) : ''; //include_once('class.upload.php'); $hup = new upload($file); //chmod($output_dir, 0755); if($hup->uploaded){ $hup->image_resize = true; $hup->image_y = $height; $hup->image_x = $width; $hup->image_ratio = true; $hup->jpeg_quality = 95; $hup->image_ratio_no_zoom_in = true; $hup->file_new_name_body = $filename; $hup->Process($dlink); if($hup->processed){ }else{ //echo 'failed'; } if($thumbPath != ''){ $hup->image_resize = true; $hup->image_y = 100; $hup->image_x = 150; $hup->image_ratio = true; $hup->jpeg_quality = 95; $hup->image_ratio_no_zoom_in = true; $hup->file_new_name_body = $filename; $hup->Process($thumbPath); if($hup->processed){ }else{ } } } }*/ function allow_image_type() { return array( '.gif', '.jpg', '.jpeg', '.png' ); } function allow_document_type() { return array( '.pdf', '.doc', '.docx', '.xls', '.xlsx' //, '.ppt', '.pptx' ); } function get_file_type($filename) { $_filename = strtolower($filename); $_arr = explode('.', $_filename); $filetype = '.' . end($_arr); return $filetype; } // ################## ชนิดของไฟล์เสี่ยงต่อความปลอดภัยของระบบ ############### function check_file($userfilename, $check_type = ''){ $arr = explode('.', $userfilename); $strings = strtolower('.'.end($arr)); if($strings == '.php' || $strings == '.asp'){ echo "<center><br>ไม่อนุญาตให้ Upload ไฟล์ชนิดนี้ <br>เนื่องจากชนิดไฟล์เสี่ยงต่อความเสียหายของระบบ <br>และขนาดไฟล์ต้องไม่เกิน 2 Mb.<br><br>"; exit; }else{ if($check_type == 'image'){ if(in_array($strings, allow_image_type())){ return 'OK'; }else{ // return 'no_image'; echo"<center><br>ชนิดไฟล์ไม่ถูกต้อง <br>ไฟล์ต้องมีนามสกุลเป็น .gif หรือ .jpg หรือ .png เท่านั้น <br>และขนาดไฟล์ต้องไม่เกิน 2 Mb.<br><br>"; echo"<a href='javascript:history.back()'><font color='ff0000'>[แก้ไขใหม่]</font></center></a><br><br>"; exit; } }else if($check_type == 'document'){ if(in_array($strings, allow_document_type())){ return 'OK'; }else{ // return 'no_document'; echo "<center><br>ชนิดไฟล์ไม่ถูกต้อง <br>ไฟล์ต้องมีนามสกุลเป็น .pdf, .doc, .docx, .xls, .xlsx เท่านั้น <br><br>"; echo"<a href='javascript:history.back()'><font color='ff0000'>[แก้ไขใหม่]</font></center></a><br><br>"; exit; } }else if($check_type == 'banner'){ if(in_array($strings, allow_image_type()) || $strings == '.swf'){ return 'OK'; }else{ // return 'no_image'; echo"<center><br>ชนิดไฟล์ไม่ถูกต้อง <br>ไฟล์ต้องมีนามสกุลเป็น .gif หรือ .jpg หรือ .png หรือ .swf เท่านั้น <br><br>"; echo"<a href='javascript:history.back()'><font color='ff0000'>[แก้ไขใหม่]</font></center></a><br><br>"; exit; } // }else if($check_type == ''){ }else{ if($check_type != ''){ if(in_array($strings, allow_image_type())){ return 'OK'; }else{ echo"<center><br>ไฟล์ที่ $check_type ชนิดไฟล์ไม่ถูกต้อง <br>ไฟล์ต้องมีนามสกุลเป็น .gif หรือ .jpg หรือ .png เท่านั้น <br>และขนาดไฟล์ต้องไม่เกิน 2 Mb.<br><br>"; echo"<a href='javascript:history.back()'><font color='ff0000'>[แก้ไขใหม่]</font></center></a><br><br>"; exit; } }else{ return 'OK'; } } } } // ############## สร้างชื่อไฟล์ใหม่ function create_filename($userfilename){ $strings = get_file_type($userfilename); $str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"; $pic1 = substr(str_shuffle($str), 0, 12); $name1="$pic1$strings"; return ($name1); } ?>