|
 |
|
จะแยกส่วนการอัพโหลดรูปจากโค้ดที่มีอยู่ เป็นฟังก์ชั่นอัพโหลดรูปยังไงครับ |
|
 |
|
|
 |
 |
|
เป็นโค้ดมัลติอัพโหลดรูปรีไซต์และรีเนมรูป คือผมจะเอาโค้ดนี้ไปเขียนเป็นฟังชันได้ยังไง เรียกใช้ยังไง แล้วส่งค่ากลับมาให้ 2ค่า คือ full_images กับ news_images จะต้องแก้ตรงไหน แล้วเรียกใช้ยังไง แล้วจะรับค่าที่กลับมายัง เพิ่งจะหัดเขียนฟังชั่นครับ ช่วยส่อนที ว่าต้องแก้ตรงไหนยังไงบ้าง ขอบคุณครับ
Code (PHP)
<?
$adt_cat_id=$_POST["adt_cat_id"];
for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++)
{
if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"][$i];
$images_file = $_FILES["fileUpload"]["type"][$i];
$images_time = date('YmdHis');
srand((double)microtime()*10); //ทำการสุ่มชื่อ
$Pic_name=$random_pic = rand(1,99);
if( $images_file == "image/gif" )
{
$filename = $Pic_name.".gif";
}
if (($images_file=="image/jpg")||($images_file=="image/jpeg")||($images_file=="image/pjpeg"))
{
$filename = $Pic_name.".jpg";
}
$full_images = "full"."$images_time"."$filename";
$new_images = "thumbs"."$images_time"."$filename";
copy($_FILES["fileUpload"]["tmp_name"][$i],"adtpics/".$full_images);
$width=150; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
if( $images_file == "image/gif" )
{
$images_orig = ImageCreateFromGIF($images);
}
if (($images_file=="image/jpg")||($images_file=="image/jpeg")||($images_file=="image/pjpeg"))
{
$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);
ImageGIF($images_fin,"adtpics/".$new_images);
ImageJPEG($images_fin,"adtpics/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
//*** Insert Record ***//
$objConnect = mysql_connect("sql201.thport.com","thpor_5994385","hikaru") or die("Error Connect to Database");
$objDB = mysql_select_db("thpor_5994385_mushroom");
$strSQL = "INSERT INTO gallery ";
$strSQL .="(Thumbnails,FilesName,gallerycat) VALUES ('".$new_images."','".$full_images."','".$adt_cat_id."')";
$objQuery = mysql_query($strSQL);
}
}
echo "<H3>เพิ่มรูปเรียบร้อยแล้ว</H3>";
print"<meta http-equiv=\"refresh\" content=\"3;URL=galleryform.php\">\n";
?>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2010-08-02 15:30:41 |
By :
hikaru034 |
View :
875 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
ก็สร้างไฟล์อีก 1 ไฟล์ครับ เป็นไฟล์สำหรับใส่ control ประเภท txtbox ,browe แล้วก็ submit อะไรก็ว่าไป
แล้วก็กำหนด action ไปที่ไฟล์ upload.php ของนายนั้นแหลครับ
แล้วก็ดูเรื่องตัวแปลทด้วยครับให้มันตรงกัน
|
ประวัติการแก้ไข 2010-08-02 15:41:41
 |
 |
 |
 |
Date :
2010-08-02 15:40:54 |
By :
Mr.Poo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ใช่ครับ จริงๆกันก็ใช้ได้อยู่ สร้างครบหมดแล้ว แต่ต้องการจะเอาโค้ดส่วนของการอัพโหลดรูป ไปสร้างเป็นฟังชั่น จะได้สะดวกในการใช้งานอ่ะครับ แบบเรียกจากส่วนอื่นๆ ที่จะใช้การอัพโหลดรูปก็เรียกไปตัวนี้ไปใช้ได้เลย
อีกอย่างที่ผมไม่เข้าใช้ คือ โค้ดนี้เวลารันที่เครื่องตัวเองมันก็ปกติดี แค่พอลงโฮสต์ปัญหาเกิด มันอัพรูปไม่ครบตามที่เราใส่มาแต่บันทึกข้อมูลซ้ำเข้าฐานข้อมูลเฉยเลย เช่น อัพไปทีเดียว 5 รูป มันบันทึกข้อมูลลงฐานข้อมูล 5แถว แต่ซ้ำซะ 2-3 แถว รูปก็ขึ้นไม่ครบ
|
 |
 |
 |
 |
Date :
2010-08-02 15:58:05 |
By :
hikaru034 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าลอง
|
 |
 |
 |
 |
Date :
2010-08-02 16:05:42 |
By :
wanon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|