Viewing file: uploadnews.php (2.82 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php include('class.uploader.php'); include('config.php'); $catid =$_GET['article_id']; $today = date("Y-m-d"); // รูปภาพปก if(trim($_FILES['files_thumb']['tmp_name']) != '') {
//$numrow=$db->query('SELECT count(cat_id) as numrow FROM cat_news'); //$numrow = $numrow->fetch_row(); $numrow=rand(); //$numrow=$numrow+1;
$images = $_FILES['files_thumb']['tmp_name']; $file = strtolower($_FILES['files_thumb']['name']); $type= strrchr($file,"."); $unixTime = date("d-m-Y_H_i_s"); $new_images = 'thumbnails_'.$unixTime.$type; //move_uploaded_file($_FILES['files_thumb']['tmp_name'],'Thumbnails/'.$new_images); $width=700; //*** Fix Width & Heigh (Autu caculate) ***// $size=GetimageSize($images); $height=round($width*$size[1]/$size[0]); $images_orig = ImageCreateFromJPEG($images); $photoX = ImagesX($images_orig); $photoY = ImagesY($images_orig); $images_fin = ImageCreateTrueColor($width, $height); ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY); ImageJPEG($images_fin,'Thumbnails/'.$new_images); ImageDestroy($images_orig); ImageDestroy($images_fin); }
$s_homename =$_POST['homename']; $s_detail=$_POST['detail']; //error_reporting(0); if(isset($_FILES['files']['name'])): define ("MAX_SIZE","8000"); $fetch_cat=$db->query("INSERT INTO cat_news(home_cat,home_name,thumbnail,detail,date_post)VALUES('$numrow','$s_homename','$new_images','$s_detail','$today')"); for($i=0; $i<count($_FILES['files']['name']); $i++) { $size=filesize($_FILES['files']['tmp_name'][$i]); if($size < (MAX_SIZE*1024)): $path = "uploads/"; $numrow1=rand(); $name = $_FILES['files']['name'][$i]; $size = $_FILES['files']['size'][$i]; list($txt, $ext) = explode(".", $name); date_default_timezone_set ("Asia/Bangkok"); $currentdate=date("d M Y"); $file= time().substr(str_replace(" ", "_", $numrow1), 0); $info = pathinfo($file); $filename = $file.".".$ext; if(move_uploaded_file($_FILES['files']['tmp_name'][$i], $path.$filename)) : $fetch=$db->query("INSERT INTO tbl_news(image_name,home_id) VALUES('$filename','$numrow')"); if($fetch): header('Location:../news_dashboard.php'); else : $error ='Data not inserting'; endif; else : $error = 'File moving unsuccessful'; endif; else: $error = 'You have exceeded the size limit!'; endif; } else: $error = 'File not found!'; endif; ?> <h2><?php echo @$error ?></h2> <a href="index.php">Try Again</a> <?php function onFilesRemoveCallback($removed_files){ foreach($removed_files as $key=>$value){ $file = 'uploads/' . $value; if(file_exists($file)){ unlink($file); } } return $removed_files; } ?>
|