|
 |
|
รบกวนช่วยดู code ให้หน่อยค่ะ คือว่าบันทึกค่าของไฟล์ที่อัพโหลดรูปภาพลงฐานข้อมูลไม่ได้ค่ะ |
|
 |
|
|
 |
 |
|
//----------------------------------- Insert news ---------------------------------------------//
Code
if(isset($_POST['submit'])=="submit"){
for($i=0;$i<count($_FILES["filUpload"]["name"]);$i++)
{
if($_FILES["filUpload"]["name"][$i] != "")
{
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"][$i],"myfile/".$_FILES["filUpload"]["name"][$i]))
{
echo "Copy/Upload Complete<br>";
}
else{ echo "Upload not complete"; }
}
}
$pro_id=$_POST['txtid'];
$name=$_POST['txtname'];
$pro_cost=$_POST['txtcost'];
$pro_price=$_POST['txtprice'];
$pro_detail=$_POST['Txtdetail'];
$pro_chest=$_POST['txtchest'];
$pro_hip=$_POST['txthip'];
$pro_length=$_POST['txtlength'];
$pro_quantity=$_POST['txtquantity'];
$pro_store=$_POST['txtstore'];
$pro_wg=$_POST['txtwg'];
$pro_introduce=$_POST['introduce'];
$sql= "INSERT INTO product (pro_id,cate_id,pro_name,pro_cost,pro_price,pro_pic, pro_pic2,pro_detail,pro_chest,pro_hip,pro_length,pro_quantity, pro_store,pro_wg,pro_introduce) VALUES ('$pro_id','$cate_id','$name','$pro_cost','$pro_price', '$_FILES','$_FILES','$pro_detail','$pro_chest','$pro_hip', '$pro_length','$pro_quantity','$pro_store','$pro_wg','$pro_introduce')";
$result=mysql_query($sql);
echo" <br><br><center><font color=red><H3>Insert Complete</H3></font></center>";
//echo"<meta http-equiv='refresh' content='1;URL=detail_shop.php'>";
}
ทำไมบันทึกไฟล์รูปลงฐานข้อมูลไม่ได้ค่ะ รบกวนช่วยดู code ให้หน่อยค่ะ
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2011-06-09 15:58:41 |
By :
som_mona2 |
View :
900 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รับค่า $_FILES ตรงๆเลยไม่ได้ครับ
ต้องกำหนดด้วยว่าจะเก็บอะไร name,size,type น่ะครับ
แบบข้างบนผม งง โค้ดอยู่ อิอิ
*** ดูโค้ดดีๆครับ ผมว่าทำตามผมแล้วก็อาจจะยังเข้าฐานข้อมูลได้ไม่สมบูรณ์
แต่ให้เอาชื่อรูปใส่ตัวแปรก่อนน่ะครับ ค่อยนำไป Query Insert
Code (PHP)
$FileName = $_FILES["filUpload"]["name"][$i]; // ชื่อรูป
$sql= "INSERT INTO product (.......,pro_pic,.........,........,.) VALUES (.........,......,'$FileName ','$_FILES',....,...)"; // ผมย่อ Query คุณเฉยๆน่ะครับ
|
ประวัติการแก้ไข 2011-06-09 16:10:30
 |
 |
 |
 |
Date :
2011-06-09 16:06:53 |
By :
mangkunzo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ความจริงเราไม่สามารถบันทึกรูปเข้าไปในฐานข้อมูลได้ ครับเพียงแต่ เราสามารถบันทึก
ไดเรคทอรี่ (ที่เก็บ)ของไฟล์รูปได้ครับ
เช่น
ปล จากการ อับโหลดจากฟอร์มนี้
Code (PHP)
<form action="" method = "post" enctype="multipart/form-data">
<input type="file" name="fileupload">
<input name="submit" type="submit" id="submit" value="submit" />
</form>
Code (PHP)
$p_temp=$_FILES[fileupload][tmp_name];
echo $p_temp."<br>"; //แสดง ชื่อที่ตั้ง Temp File
$p_name=$_FILES[fileupload][name];
echo $p_name."<br>"; // ชื่อมัน
$p_size=$_FILES[fileupload][size];
echo $p_size."<br>"; // คาหนาด
$p_type=$_FILES[fileupload][type];
echo $p_type; //ชนิดไฟล์
//------------------Code upload ----------
$fileimgname = "img_".date("ymdhis").".jpg"; //--------[1]ตั้งชื่อภาพใหม่ กันไม่ให้ซ้ำกัน
copy($p_temp,"Photo/".$fileimgname); // --------------[1] ภาพไปที่ โฟล์เดอร์ Photo แล้ว แต่ ฐานข้อมุลยังไม่มี
$fileimgname2 = $p_name; //-----------------[2]เอาชื่อมันเอง
copy($p_temp,"Photo/".$p_name); // --------------[2] ภาพไปที่ โฟล์เดอร์ Photo แล้ว แต่ ฐานข้อมุลยังไม่มี
//----------------------------------------------
ตรงส่วนของ insert into ก็นำชื่อ ดังกล่าว ($fileimgname หรือ $fileimgname2) ไปเก็บใน ฐานข้อมูลเพื่อเรียกใช้อีกที
|
ประวัติการแก้ไข 2011-06-09 16:14:53
 |
 |
 |
 |
Date :
2011-06-09 16:12:44 |
By :
compeng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
'$FileName ','$_FILES',....,...)";
ทำไมถึงไม่เป็น $FileName ทั้งสองอันเลยคะ รบกวนช่วยตอบด้วยนะคะ
|
 |
 |
 |
 |
Date :
2011-06-09 16:27:10 |
By :
som_mona2 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มือใหม่หัดทำ ต้องขอโทษด้วยนะคะ ถ้าทำให้ งง อิอิ
|
 |
 |
 |
 |
Date :
2011-06-09 17:07:22 |
By :
som_mona2 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|