|
 |
|
สอบถามเกี่ยวกับการ ดักชนิดไฟล์และขนาดไฟล์ได้อย่างไร..... |
|
 |
|
|
 |
 |
|
แนะจะเพิ่มโค้ดเกี่ยวกับการ ดักชนิดไฟล์และขนาดไฟล์ได้อย่างไรครับ
คือโค้ดผมจะเป็นแบบ มัลติอัพโหลด
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
include("../../../includes/config.inc.php");
$id = $_POST['v_id'];
$sql = "SELECT * FROM school_gallery_category where gallery_category_id = '$id'";
$query = mysql_query($sql)or die("Error Query [".$sql."]");
$row = mysql_fetch_array($query);
$dir_img = $row['gallery_category_id'];
$dir_thumb= $row['gallery_category_id']."/thumb";
if(!file_exists($dir_img)&&!file_exists($dir_thumb)){
mkdir($dir_img);
mkdir($dir_thumb);
}
for($i=0;$i<count($_FILES["upfile"]);$i++){
if($_FILES["upfile"]["name"][$i] != ""){
$path = $dir_img."/".$_FILES["upfile"]["name"][$i];
if(move_uploaded_file($_FILES["upfile"]["tmp_name"][$i],$path)){
$gallery_filename = $_FILES["upfile"]["name"] [$i];
$gallery_thumb = "thumb_".$_FILES["upfile"]["name"] [$i];
$gallery_caption = trim($_REQUEST['caption'][$i]) ;
//echo $gallery_caption;
$sql = "INSERT into school_gallery (gallery_image_id,gallery_filename,gallery_thumbname,gallery_caption,gallery_category_id ) values ('' , '$gallery_filename' , '$gallery_thumb','$gallery_caption','$id' ) ";
mysql_query($sql);
$thumb_path = $dir_thumb."/thumb_".$_FILES["upfile"]["name"][$i];
list($w1, $h1) = getimagesize($path); // Get new dimensions
$quality = 100;
$w2 = 100 ; #
$percent = $w2 / $w1 ;
$h2 = $h1 * $percent ;
$h2 = 80 ; #
$percent = $h2 / $h1 ;
$w2 = $w1 * $percent ;
$w2 = 120 ; #
$h2 = 90 ; #
$im = imagecreatetruecolor($w2+4, $h2+4);
$im1 = imagecreatefromjpeg($path);
$dark = imagecolorallocate($im,185,185,185); // dark
$light = imagecolorallocate($im,230,230,230);
$white = imagecolorallocate($im,254,254,254);
imagefilledrectangle($im, 0, 0, $w2+3 , $h2+3, $white);
imagefilledrectangle($im, 4, 4, $w2+4 , $h2+4, $light);
imagefilledrectangle($im, 3, 3, $w2+2 , $h2+2, $dark);
imagecopyresampled($im, $im1, 0, 0, 0, 0, $w2, $h2, $w1, $h1);
imagestring($im, 5, 5, $h2 - 20, "", $light);
imagejpeg($im, $thumb_path , $quality); # %
imagedestroy($im);
imagedestroy($im1);
}
}
}
echo "<script>window.location='galleryform.php'</script>" ;
?>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2011-01-25 01:58:34 |
By :
tummavong |
View :
880 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 03
|