|
 |
|
มีคำถามเกี่ยวกับการอัพโหลดไฟล์รูปลง mysql ค่ะ เขียนแล้วไม่ได้สักทีค่ะ |
|
 |
|
|
 |
 |
|
อยากอัพโหลดรูปลง ใน mysql แต่เขียนโปรแกรมยังไงก็ทำไม่ได้สักทีค่ะ รบกวนดูโค้ดให้หน่อยนะคะ ^.^
Code (PHP)
<?
session_start();
if ($sess_adminid<>session_id()) {
header( "Location: admin.php"); exit();
}
$name=$_POST[name];
$sex=$_POST[sex];
$fileupload=$_FILES['fileupload']['tmp_name'];
$fileupload_name=$_FILES['fileupload']['name'];
$fileupload_size=$_FILES['fileupload']['size'];
$fileupload_type=$_FILES['fileupload']['type'];
if ($name=="") {
echo "<H3>ERROR : กรุณากรอก ข้อมูลให้ครบถ้วน</H3>";
exit();
}
include "connect.php";
$sql="INSERT INTO tb_pattern VALUES('','$name','','$sex',null)";
$result=mysql_db_query($dbname,$sql);
if ($fileupload) {
$array_last=explode(".",$fileupload_name);
$c=count($array_last)-1;
$lastname=strtolower($array_last[$c]) ;
if ($lastname=="gif" or $lastname=="jpg" or $lastname=="jpeg") {
$sql2="select max(id_patt) from tb_pattern ";
$result2=mysql_db_query($dbname,$sql2);
$row=mysql_fetch_row($result2);
$photoname=$row[0].".".$lastname;
copy($fileupload,"photo/".$photoname);
$sql3="update tb_pattern set image='$photoname' where id_patt ='$row[0]' ";
$result3=mysql_db_query($dbname,$sql3);
}
unlink($fileupload);
}
if ($result) {
echo "<H3>เพิ่ม ประเภทสินค้าเรียบร้อยแล้ว</H3>";
echo "[ <A HREF=admin_pat.php>คลิกเพื่อกลับ</A> ] ";
} else {
echo "<H3>ERROR : ไม่สามารถเพิ่มประเภทสินค้าได้</H3>";
}
mysql_close();
?>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2011-08-25 20:32:39 |
By :
mirage_niji --บี |
View :
2736 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตาลายแล้วครับ เอาเป็นว่าดูบทความนี้แล้วกันครับ ง่าย ๆ
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"myfile/".$_FILES["filUpload"]["name"]))
{
echo "Copy/Upload Complete<br>";
//*** Insert Record ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "INSERT INTO files ";
$strSQL .="(Name,FilesName) VALUES ('".$_POST["txtName"]."','".$_FILES["filUpload"]["name"]."')";
$objQuery = mysql_query($strSQL);
}
?>
<a href="PageUploadToMySQL3.php">View files</a>
</body>
</html>
Go to : PHP สร้างฟอร์มสำหรับ Upload รูปภาพลงในฐานข้อมูล MySQL พร้อมกับแบบ Form สำหรับการแก้ไขรูปภาพ
|
 |
 |
 |
 |
Date :
2011-08-25 21:41:12 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อีกอันเป็น BLOB ครับ เก็บลงใน MySQL ฟิวด์ครับ
Code (PHP)
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM files WHERE FilesID = '".$_GET["FilesID"]."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
echo $objResult["FilesName"];
?>
Go to : PHP Upload MySQL BLOB Image (BLOB Binary Data in a MySQL Database)
|
 |
 |
 |
 |
Date :
2011-08-25 21:42:00 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณ คุณ mr.win มากๆนะคะ
จริงๆ ก็ไม่ได้เขียนโค้ดเองค่ะ แค่เอาโค้ดจากในหนังสือมาแปะ แต่ประยุกต์ให้แล้วไม่ได้
อิอิ
|
 |
 |
 |
 |
Date :
2011-08-26 20:42:18 |
By :
mirage_niji |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|