|
 |
|
ขอรบกวนถาม เกียวกับ การ แปลงชือไฟล์ภาพ ก่อน เก็บลง host |
|
 |
|
|
 |
 |
|
ก่อนทำความเข้าใจก่อนครับว่าโค้ดมันมี 2 ส่วน ส่วนนึงย้ายไฟล์(moveupload) และอีกส่วนนึงบันทึกลงฐานข้อมูล(INSERT INTO) . ..
*ขอละส่วนที่ 2 INSERT INTO ไว้ในฐานที่เข้าใจ
เอานี่ไปลองดูว่าจะเกิดอะไรขึ้นนะครับ
$aaa="xd8888".$_FILES["browse"]["name"];
if(move_uploaded_file($_FILES["browse"]["tmp_name"],"home_student/".$aaa))
{
echo "Copy/Upload Complete";
}
ปล. ต่อท้ายจะยุ่งยากนะครับ เพราะมันมีนามสกุลอยู่เช่น xxx.png_home ไอหย่าจะอ่านได้ยังต้องไปตรวจนามสกุลอีก . .. ดังนั้นเพิ่มยัดไปข้างหน้าดีกว่านะคร้าบ
|
ประวัติการแก้ไข 2013-10-02 11:25:45
 |
 |
 |
 |
Date :
2013-10-02 11:23:15 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
//จะทำอะไรก็ตาม เก็บค่าในตัวแปร (Variable) ให้เรียบร้อยเพื่อความสะดวกในการใช้งาน
$browse_tmp=$_FILES["browse"]["tmp_name"];
$browse_name=$_FILES["browse"]["name"];
$explode=explode(".",$browse_name); //
$rename=$explode[0]."-".rand().".".$explode[1]; //เปลี่ยนชื่อไฟลร์ และ random เพื่อไม่ให้มีปัญหาต่อการเซฟแคสของ browser
//$rename="student-".rand().".".$explode[1]; // สามารถสร้างชื่อได้ใน "student-" ได้เลย
if(copy($browse_tmp,"home_student/".$rename)){ // copy file เข้าสู้ patch
$insert=mysql_query("insert into (picture) VALUES ('".$rename."')") or die (mysql_error()); // เมื่อเงื่อไขเป็นจริง insert
}
?>
|
ประวัติการแก้ไข 2013-10-02 13:25:02
 |
 |
 |
 |
Date :
2013-10-02 13:24:42 |
By :
Ex-[S]i[L]e[N]t |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|