Mon 31 Mar 2008 21:22:35
พอรู้วิธีเขียนโค๊ด php แบบอัพโหลดรูปแล้วรีขนาดภาพไหม
ตัวอย่าง สมมุติมีรูป 800*600 นำไปอัพโหลดลงเว็บของเราให้มันรีไซให้เป็น 370*287
ระหว่างเราอัพโหลดรูปให้มัน รีขนาดรูปด้วย อ่าคับ อยากได้มากๆเลย
Mon 31 Mar 2008 21:23:42
ช่วยตอบหน่อยคับ
Mon 31 Mar 2008 21:40:01
Tue 1 Apr 2008 01:18:16
Tue 1 Apr 2008 09:28:07
ขอบคุณพี่เว็บมาสเตอร์คับ
Tue 1 Apr 2008 10:31:13
ก็ทำมะถูกอยู่ดีอ่า >_<
Tue 1 Apr 2008 10:45:14
ช่วยดูทีสิ อันนี้อัพโหลดไฟล อัพรูปก็ได้
index.php
<form action="Upphotos.php" method="post" enctype="multipart/form-data" name="bigchernForm" id="bigchernForm">
<div id="body"> เลือกรูปที่จะส่ง
<table class="input" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="20"> *ท่านสามารถส่งรูปมาในรูปแบบของไฟล์ .zip ได้เพื่อความสะดวกของท่าน<br />
*ไฟล์ที่จะส่งมาไม่ควรมีขนาดเกิน 150 MB </td>
</tr>
<tr>
<td> รูป 1 :
<input type="file" name="bigchernFile[]" id="bigchernFile" class="filebox" />
</td>
</tr>
<tr>
<td> รูป 2 :
<input type="file" name="bigchernFile[]" id="bigchernFile" class="filebox" />
</td>
</tr>
<tr>
<td> รูป 3 :
<input type="file" name="bigchernFile[]" id="bigchernFile" class="filebox" />
</td>
</tr>
<tr>
<td> รูป 4 :
<input type="file" name="bigchernFile[]" id="bigchernFile" class="filebox" />
</td>
</tr>
<tr>
<td> รูป 5 :
<input type="file" name="bigchernFile[]" id="bigchernFile" class="filebox" />
</td>
</tr>
<tr>
<td colspan="20"><input type="submit" name="bigchern" value="ส่งรูป" />
<input type="hidden" name="event" value="upload" />
</td>
</tr>
</table>
</div>
</form>
Upphotos.php
<?
/******* config *********/
$folder = 'upload/'; // โฟลเดอร์เอาไว้เก็บไฟล์ เช่น upload/ แต่อย่าลืมส้ราง โฟลเดอร์เอาไว้ด้วยหละ และอย่าลืม chamod เป็น 777
/********* param ********/
$bigchernFile = $_FILES['bigchernFile'];
$event = $_REQUEST['event'];
/********* event *******/
if($event=="upload"){
for($i=0;$i<count($bigchernFile['name']);$i++){
if(is_file($bigchernFile['tmp_name'][$i])){
echo $bigchernFile['name'][$i]." อัพโหลดเรียบร้อยแล้ว<br>";
$rand = rand(1111,9999);
copy($bigchernFile['tmp_name'][$i],$folder.$rand.$bigchernFile['name'][$i]);
/* ถ้าอยากเก็บชื่อไฟล์ลง database ก็เก็บตรงนี้ เรียกตัวแปร $bigchernFile['name'][$i] ใช้งานได้เลย */
}
}
echo "<script> alert('bigchern upload complete');</script>";
echo '<meta http-equiv="refresh" content="3; URL=index.php">';
exit();
}
?>
**ต้องสร้างโฟลเดอร์ upload ด้วย คือช่วยแก้ให้มันรีขนาดได้ไหม อย่างเช่นอัพรูป มีขนาดใหญ่ให้มันเก็บขนาดรูปให้เล็กลง จาก 800*600 พออัพโหลดเข้าเซฟเวอร์ เหลือขนาด 370*287
Tue 1 Apr 2008 13:42:28
แง่มะมีใครตอบ -*- รอ เว็บมาสเตอร์คนเดียวเลยงิ
Tue 1 Apr 2008 15:33:23
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<form name="form1" enctype="multipart/form-data" method="post" action="">
<table width="900" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td width="216" valign="top"><div align="right">รูป : </div></td>
<td width="684"><input name="file" type="file" ></td>
</tr>
<tr>
<td> </td>
<td><input name="addnews" type="submit" id="addnews" value="ส่งข้อมูลเข้าสู่ดาต้าเบส" /></td>
</tr>
</table>
</form>
<?php
if(isset($_POST["addnews"]))
{
$images = $_FILES["file"]["tmp_name"];
$width = 210;
$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,$file_name);
ImageJPEG($images_fin,$file);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
$picture = $file_name;
echo '<img src="',$picture,'">';
}
?>
ได้แล้วจ๋า ขอบคุงงิ

















