|
 |
|
ช่วยแก้โค้ดอัพรูป ครั้งละหลายรูปให้หน่อยคับ ผมอยากเปลี่ยนชื่อรูปอะคับคือผมได้รับค่า $id_image |
|
 |
|
|
 |
 |
|
ผมอยากเปลี่ยนชื่อรูปอะคับ
คือผมได้รับค่า $id_image มาจากอีกฟอร์ม สมมุติว่า $id_image มีข้อมูล อยู่ที่ 1,2,3 ตามละดับ
แล้วได้ทำการอัพรูป มา 4 รูป ซึ่งสามารถอัพรูปแล้ว resize ได้ตามปกติ
แต่ผมอยากให้ ชื่อรูปเปลี่ยนไปตามจำนวนข้อมูล $id_image ที่รับมาคับ ถ้ารับมา 4 รูป ชื่อรูปก็จะเปลี่ยนเป็น 4.jpg,5.jpg,6.jpg,7.jpg ตามลำดับคับ
จะเขียน array ยังไงคับ ผมงงมากคับ
ขอบคุณคับ
Code (PHP)
<?
$id_image=$_POST[id_image];
for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++) {
if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "") {
$filetype=$_FILES['fileUpload']['type'][$i];
$filesize=$_FILES['fileUpload']['size'][$i];
if($filesize > 2000000){
echo"<script>alert('ขนาดของไฟล์รูปภาพต้องไม่เกิน 1 MB');history.back();</script>";
exit();
}
if ($filetype!="image/pjpeg" and $filetype!="image/jpeg" ){
echo"กรณาอัพเฉพาะไฟล์ JPGเท่านั้น ";
echo "<br><a href='javascript:history.back()'>กลับไป</a>";
exit;
}
$images = $_FILES["fileUpload"]["tmp_name"][$i];
copy($_FILES["fileUpload"]["tmp_name"][$i],"../module/gallery/images/".$_FILES["fileUpload"]["name"][$i]);
$new_images =$b[a].$_FILES["fileUpload"]["name"][$i];// ติดตรงนี้คับ
$width=100; //*** 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,"../module/gallery/images/resize/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
echo "Resize Successful.<br>";
}
}
}
?>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-01-24 00:15:29 |
By :
nammont |
View :
1782 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?
$id_image=$_POST[id_image];
for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++) {
if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "") {
$filetype=$_FILES['fileUpload']['type'][$i];
$filesize=$_FILES['fileUpload']['size'][$i];
if($filesize > 2000000){
echo"<script>alert('ขนาดของไฟล์รูปภาพต้องไม่เกิน 1 MB');history.back();</script>";
exit();
}
if ($filetype!="image/pjpeg" and $filetype!="image/jpeg" ){
echo"กรณาอัพเฉพาะไฟล์ JPGเท่านั้น ";
echo "<br><a href='javascript:history.back()'>กลับไป</a>";
exit;
}
$images = $_FILES["fileUpload"]["tmp_name"][$i];
copy($_FILES["fileUpload"]["tmp_name"][$i],"../module/gallery/images/".$_FILES["fileUpload"]["name"][$i]); // ภาพเดิมไม่เปลี่ยนชื่อใช่มั๊ย
$new_images = $id_image+$i+1.'.jpg'; // ลองดูนะว่าได้รึป่าว ค่า $id_image ที่รับมาเป็น 3 ใช่มั๊ย
$width=100; //*** 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,"../module/gallery/images/resize/".$new_images); // เปลี่ยนชื่อภาพเฉพาะ resize
ImageDestroy($images_orig);
ImageDestroy($images_fin);
echo "Resize Successful.<br>";
}
}
// } อันนี้รู้สึกจะใส่เกินมานะ
?>
|
 |
 |
 |
 |
Date :
2010-01-24 01:07:11 |
By :
kennyg |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณคับ คุณMoo คับ  
บรรทัดที่ 23 ใช้ไม่ได้คับ
ผมเลยแยกออกมาคับ
$c=$id_image+$i; เลข +1 ไม่ได้เดี๋ยวภาพเกิน 
$new_images = $c.".jpg";
ตอนนี้ได้แล้วคับ เปลี่ยน ทั้ง ภาพเดิมและภาพ resize เลยคับ  
อยากได้วิธีการ resize ภาพ .gif กับ png คับ
|
 |
 |
 |
 |
Date :
2010-01-24 01:33:32 |
By :
nammont |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|