|
 |
|
ช่วยแก้ code ดักข้อมูล upload multiple ทีค่ะ [quote]code แรกเป็น code ดักค่ะข้อมูลค่ะ จะทำไปแทรกตรง code ล่างยังไงดีค่ะ |
|
 |
|
|
 |
 |
|
Quote:code แรกเป็น code ดักค่ะข้อมูลค่ะ จะทำไปแทรกตรง code ล่างยังไงดีค่ะ
Code (PHP)
$Max_File_Size = 3000000; //กำหนดขนาดไฟล์ที่ใหญ่ที่สุดที่อนุญาตให้ upload มาที่ Server มีหน่วยเป็น byte
$File_Type_Allow = array("image/pjpeg" /*.jpg, .jpeg*/,
"image/jpeg" /* .jpg, .jpeg*/); //กำหนดประเภทของไฟล์ว่าไฟล์ประเภทใดบ้างที่อนุญาตให้ upload มาที่ Server
function validate_form($file_input,$file_size,$file_type) { //เป็น function ที่เอาไว้ตรวจสอบว่าไฟล์ที่ผู้ใช้ upload ตรงตามเงื่อนไขหรือเปล่า
global $Max_File_Size,$File_Type_Allow;
if ($file_input == "none") {
$error = "<CENTER><p>ไม่มี file ให้ Upload<p><a href=javascript:history.back(); >กลับไปแก้ไข</p></CENTER>";
} elseif ($file_size > $Max_File_Size) {
$error = "<CENTER><p>ขนาดไฟล์ใหญ่กว่า $Max_File_Size ไบต์ <p><a href=javascript:history.back(); >กลับไปแก้ไข</p></CENTER>";
} elseif (!check_type($file_type,$File_Type_Allow)) {
$error = "<CENTER><p>ไฟล์ประเภทนี้ ไม่อนุญาตให้ Upload<p><a href=javascript:history.back(); >กลับไปแก้ไข</p></CENTER>";
} else {
$error = false;
}
return $error;
}
function check_type($type_check) { //เป็นฟังก์ชัน ที่ตรวจสอบว่า ไฟล์ที่ upload อยู่ในประเภทที่อนุญาตหรือเปล่า
global $File_Type_Allow;
for ($i=0;$i<count($File_Type_Allow);$i++) {
if ($File_Type_Allow[$i] == $type_check) {
return true; }
}
return false;
}
$error_msg = validate_form($_FILES["filUpload"],$_FILES["filUpload"]["size"],$_FILES["filUpload"]["type"]);
if ($error_msg) {
echo $error_msg;
} else {
Quote:เอาไปใส่ตรงไหนดี
Code (PHP)
<?
include("config.inc.php");
mysql_connect($hostname, $user, $password) or die("ติดต่อฐานข้อมูลไม่ได้");
mysql_select_db($dbname) or die("เลือกฐานข้อมูลไม่ได้");
mysql_query("SET NAMES UTF8");
$job_code=$_POST["job_code"];
for($i=0;$i<count($_FILES["filUpload"]["name"]);$i++)
{
if($_FILES["filUpload"]["name"][$i] != "")
{
if(copy($_FILES["filUpload"]["tmp_name"][$i],"../upload/".$_FILES["filUpload"]["name"][$i]))
{
//*** Insert Record ***//
$strSQL = "INSERT INTO tb_upload ";
$strSQL .="(upload_name,job_code) VALUES ('".$_FILES["filUpload"]["name"][$i]."','".$job_code."')";
$objQuery = mysql_query($strSQL);
}
}
}
echo "Copy/Upload Complete<br>";
?>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-04-03 23:23:23 |
By :
Ninezy |
View :
1377 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
include("config.inc.php");
mysql_connect($hostname, $user, $password) or die("ติดต่อฐานข้อมูลไม่ได้");
mysql_select_db($dbname) or die("เลือกฐานข้อมูลไม่ได้");
mysql_query("SET NAMES UTF8");
$job_code=$_POST["job_code"];
$Max_File_Size = 3000000; //กำหนดขนาดไฟล์ที่ใหญ่ที่สุดที่อนุญาตให้ upload มาที่ Server มีหน่วยเป็น byte
$File_Type_Allow = array("image/pjpeg" /*.jpg, .jpeg*/,
"image/jpeg" /* .jpg, .jpeg*/); //กำหนดประเภทของไฟล์ว่าไฟล์ประเภทใดบ้างที่อนุญาตให้ upload มาที่ Server
function validate_form($file_input,$file_size,$file_type) { //เป็น function ที่เอาไว้ตรวจสอบว่าไฟล์ที่ผู้ใช้ upload ตรงตามเงื่อนไขหรือเปล่า
global $Max_File_Size,$File_Type_Allow;
if ($file_input == "none") {
$error = "<CENTER><p>ไม่มี file ให้ Upload<p><a href=javascript:history.back(); >กลับไปแก้ไข</p></CENTER>";
} elseif ($file_size > $Max_File_Size) {
$error = "<CENTER><p>ขนาดไฟล์ใหญ่กว่า $Max_File_Size ไบต์ <p><a href=javascript:history.back(); >กลับไปแก้ไข</p></CENTER>";
} elseif (!check_type($file_type,$File_Type_Allow)) {
$error = "<CENTER><p>ไฟล์ประเภทนี้ ไม่อนุญาตให้ Upload<p><a href=javascript:history.back(); >กลับไปแก้ไข</p></CENTER>";
} else {
$error = false;
}
return $error;
}
function check_type($type_check) { //เป็นฟังก์ชัน ที่ตรวจสอบว่า ไฟล์ที่ upload อยู่ในประเภทที่อนุญาตหรือเปล่า
global $File_Type_Allow;
for ($i=0;$i<count($File_Type_Allow);$i++) {
if ($File_Type_Allow[$i] == $type_check) {
return true; }
}
return false;
}
for($i=0;$i<count($_FILES["filUpload"]["name"]);$i++)
{
if($_FILES["filUpload"]["name"][$i] != "")
{
$error_msg = validate_form($_FILES["filUpload"]["name"][$i],$_FILES["filUpload"]["size"][$i],$_FILES["filUpload"]["type"][$i]);
if ($error_msg) {
echo $error_msg;
} else {
if(copy($_FILES["filUpload"]["tmp_name"][$i],"../upload/".$_FILES["filUpload"]["name"][$i]))
{
//*** Insert Record ***//
$strSQL = "INSERT INTO tb_upload ";
$strSQL .="(upload_name,job_code) VALUES ('".$_FILES["filUpload"]["name"][$i]."','".$job_code."')";
$objQuery = mysql_query($strSQL);
}
}
}
}
echo "Copy/Upload Complete<br>";
|
 |
 |
 |
 |
Date :
2010-04-05 03:24:52 |
By :
chineji |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|