|
|
|
สอบถามเรื่องอัพโหลดรูปแบบ multiple ลง mysql ค่ะ คือบันทึกลงไป ได้แค่ภาพสุดท้ายทั้ง 16 ฟิวค่ะ |
|
|
|
|
|
|
|
รบกวนสอบถามเรื่องอัพโหลดรูปภาพแบบ multiple ลงฐานข้อมูล mysql ค่ะ คือบันทึกลงไป ได้แค่ภาพสุดท้ายทั้ง 16 ฟิวค่ะ
code ประมาณนี้ค่ะ
Code (PHP)
<?php
$objConnect = mysql_connect("localhost","ple","AwBK") or die("Error Connect to Database");
$objDB = mysql_select_db("test");
$THdt= mktime(gmdate("H")+7,gmdate("i"),gmdate("s"),gmdate("m"),gmdate("d"),gmdate("Y") );
$date_post=date($timeformat,$THdt);
for($i = 1; $i <= 1; $i++)
{
if($_FILES["filUpload"]["name"][$i] != "")
{
sleep(1);
$nameimage="image_".date("YmdHis").$i.".jpg";
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"][$i],"../uppic/files/".$nameimage))
{
//*** Insert Record ***//
$view="0";
$strSQL = "INSERT INTO picnews";
$strSQL .="(pic1,pic2,pic3,pic4,pic5,pic6,pic7,pic8,pic9,pic10,pic11,pic12,pic13,pic14,pic15,pic16) VALUES ('$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage')";
mysql_query("set NAMES utf8");
$objQuery = mysql_query($strSQL);
}
}
}
for($i = 1; $i <=16; $i++)
{
if($_FILES["filUpload"]["name"][$i] != "")
{
sleep(1);
$nameimage="image_".date("YmdHis").$i.".jpg";
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"][$i],"../uppic/files/".$nameimage))
{
}}}
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2016-03-07 14:27:28 |
By :
conectioncode |
View :
874 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เดี๋ยวๆ จากโค๊ด คุณเข้าใจอะไรผิดหรือป่าวครับ
|
|
|
|
|
Date :
2016-03-07 14:41:28 |
By :
compiak |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
07.for($i = 1; $i <= 1; $i++)
08.{
09.if($_FILES["filUpload"]["name"][$i] != "")
10.{
11.sleep(1);
12.$nameimage="image_".date("YmdHis").$i.".jpg";
13.
14.if(move_uploaded_file($_FILES["filUpload"]["tmp_name"][$i],"../uppic/files/".$nameimage))
15.{
16.//*** Insert Record ***//
17.$view="0";
18.$strSQL = "INSERT INTO picnews";
19.
20.
21.$strSQL .="(pic1,pic2,pic3,pic4,pic5,pic6,pic7,pic8,pic9,pic10,pic11,pic12,pic13,pic14,pic15,pic16) VALUES ('$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage','$nameimage')";
22.mysql_query("set NAMES utf8");
23.$objQuery = mysql_query($strSQL);
24.}
25.}
26.}
แก้เป็น
Code (PHP)
for($i = 1; $i <= 1; $i++){
if($_FILES["filUpload"]["name"][$i] != ""){
$nm='nm'.$i;
$$nm="image_".date("YmdHis").$i.".jpg";
if(!move_uploaded_file($_FILES["filUpload"]["tmp_name"][$i],"../uppic/files/".$$nm)){
$$nm='';
}
}
}
$strSQL = "INSERT INTO picnews";
(pic1,pic2,pic3,pic4,pic5,pic6,pic7,pic8,pic9,pic10,pic11,pic12,pic13,pic14,pic15,pic16)
VALUES (
'$nm1','$nm2','$nm3','$nm4','$n5','$nm6','$nm7','$nm8',
'$nm9','$n10','$nm11','$nm12','$nm13','$nm14','$nm15','$nm16'
)";
mysql_query("set NAMES utf8");
$objQuery = mysql_query($strSQL);
การ คิวรี่เปลี่ยนไปอยู่ นอกลูป for มันทำให้ข้อมูลทับของเก่า
และเป็นการ insert หลายเรคคอร์ด
|
|
|
|
|
Date :
2016-03-08 09:24:34 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|