พบกับบทความเกี่ยวกับคอมพิวเตอร์และ programming ได้ที่ http://articles.modoeye.com | บล็อกอาหาร
PHP development / ช่วยดู code multi upload ให้หน่อยครับว่าผิดตรงไหน
GK
GK
Wed 20 Aug 2008 01:19:33

ช่วยดูให้หน่อยครับว่ามันผิดตรงไหน อัพโหลดไม่ได้ซักที

<?
include "connect.php";
include "chksession.php";


$up_photo = $_FILES['up_photo'] ['tmp_name'] ;
$photo_name=$_FILES ['up_photo'] ['name'];
$photo_size=$_FILES ['up_photo'] ['size'];
$photo_type=$_FILES ['up_photo'] ['type'];
$date = date("U");

for($i = 0 ; $i < count($up_photo) ; $i++){
  
  echo $up_photo[name][$i]."<br>" ;

  $ext=strtolower(end(explode('.', $photo_name)));
  
  if($ext=="jpg" or $ext=="jpeg" or $ext=="png" or $ext=="gif") {
  $sql="select max(id_car) from car_info";
  $result=mysql_db_query ($dbname,$sql);
  $r=mysql_fetch_array ($result);
  $id_max=$r [0];
  
  $filename=$date.".".$ext;
  copy ($up_photo,"images/$filename");
  
  if($ext=="jpg" or $ext=="jpeg"){
   $ori_img = imagecreatefromjpeg($up_photo);
   }else if ($ext=="png"){
   $ori_img = imagecreatefrompng($up_photo);
   }else if ($ext=="gif"){
   $ori_img = imagecreatefromgif($up_photo);
   }
   $ori_size=getimagesize($up_photo);
   $ori_w=$ori_size[0];
   $ori_h=$ori_size[1];
   if($ori_w>=$ori_h){
   $new_w=150;
   $new_h=80;
   }else{
   $new_h=80;
   $new_w=150;
   }
   $new_img= imagecreatetruecolor($new_w, $new_h);
   imagecopyresized(  $new_img,   $ori_img,0,0,0,0,$new_w,$new_h,$ori_w,$ori_h);
   if($ext=="jpg" or $ext=="jpeg"){
    imagejpeg($new_img,"images_small/$filename");
    }else if ($ext=="png"){
    imagepng($new_img,"images_small/$filename");
    }else if ($ext=="gif"){
    imagegif($new_img,"images_small/$filename");
    }
    imagedestroy($ori_img);
    imagedestroy($new_img);
  
  
  $sql="update car_info set image1='$filename' where id_car='$id_max' ";
  $result=mysql_db_query ($dbname,$sql);
 }


  ?>
    <script  language="vbscript">
     msgbox"¨Ñ´à¡çºÃÙ»ÀÒ¾·Õè 1 áÅéÇ ¡ÃسÒÍѾâËÅ´ÃÙ»·Õè 2"
     window.location.href="../car/car_edit.php"
     </script>
 <?
 ?>

webmaster
webmaster
Wed 20 Aug 2008 12:28:09
การที่คุณระบุ index ใน ตัว $_FILES แล้วจะได้เพียง array ของ properties ของ upload file เท่านั้น

ถ้าต้องการ upload หลายๆอันต้องใช้

foreach($_FILES as $file){
    loop ตามจำนวนไฟล์ที่ upload เข้ามาและจะมีค่า $file["name"], $file["tmp_name"], $file["size"], $file["type"]
}
Reply
Name:
E-mail:
Home | Services | Forum | Classified | Directories | Support | Contact
ATOM feed RSS 0.9 feed RSS 1.0 feed RSS 2.0 feed
Copyright © 2005 - 2007 Modoeye.com, All Rights Reserved.
Disclaimer | Privacy policy | Term of Use | Term of Services
Valid XHTML Valid CSS! PHP: Hypertext Preprocessor MySQL database Apache Powered! FreeBSD Power to serve
Modoeye Sitemap Client login