ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingขอถามเรื่อง php_upload_photo (+1 ทุกคำตอบ)
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: ขอถามเรื่อง php_upload_photo (+1 ทุกคำตอบ)  (อ่าน 1129 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
to2009
คนรักเสียว
*

พลังน้ำใจ: 40
ออฟไลน์ ออฟไลน์

กระทู้: 196



ดูรายละเอียด
« เมื่อ: 27 สิงหาคม 2012, 12:41:14 »

ผมต้องการที่จะป้องกันไม่ให้ชื่อภาพเในฐานข้อมูลขียนทับกันต้องทำไงครับ
ขอคําแนะนํา wanwan017 wanwan017
โค๊ด:
<?php 
 
 
//This is the directory where images will be saved 
 
$target "images/"
 
$target $target basename$_FILES['photo']['name']); 
 
 
//This gets all the other information from the form 
 
$name=$_POST['name']; 
 
$email=$_POST['email']; 
 
$phone=$_POST['phone']; 
 
$pic=($_FILES['photo']['name']); 
 
 
// Connects to your Database 
 
mysql_connect("localhost""root""") or die(mysql_error()) ; 
 
mysql_select_db("Database_Name") or die(mysql_error()) ; 
 
 
//Writes the information to the database 
 
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; 
 
 
//Writes the photo to the server 
 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
 { 
 
 
//Tells you if its all ok 
 
echo "The file "basename$_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"
 } 
 else { 
 
 
//Gives and error if its not 
 
echo "Sorry, there was a problem uploading your file."
 } 
 
?>
บันทึกการเข้า

รับเขียนบทความภาษาอังกฤษ ราคาถูก
1 คำ = 0.65 บาท
ขั้นต่ำ 100 คำ/บทความ
สนใจ PM มาได้
Basicman
คนรักเสียว
*

พลังน้ำใจ: 10
ออฟไลน์ ออฟไลน์

กระทู้: 178



ดูรายละเอียด
« ตอบ #1 เมื่อ: 27 สิงหาคม 2012, 12:43:20 »

 wanwan023 เติม วัน+เวลา เข้าไปหลังชื่อ น่าจะโอเค นะครับ
บันทึกการเข้า
ccsakuna
สมุนแก๊งเสียว
*

พลังน้ำใจ: 71
ออฟไลน์ ออฟไลน์

กระทู้: 696



ดูรายละเอียด เว็บไซต์
« ตอบ #2 เมื่อ: 27 สิงหาคม 2012, 12:46:14 »

wanwan023 เติม วัน+เวลา เข้าไปหลังชื่อ น่าจะโอเค นะครับ

ตามนั้น ไม่ซ้ำกันแน่นอนคะ
บันทึกการเข้า

to2009
คนรักเสียว
*

พลังน้ำใจ: 40
ออฟไลน์ ออฟไลน์

กระทู้: 196



ดูรายละเอียด
« ตอบ #3 เมื่อ: 27 สิงหาคม 2012, 12:51:28 »

wanwan023 เติม วัน+เวลา เข้าไปหลังชื่อ น่าจะโอเค นะครับ

ขอตัวย่าง code ได้ใหมครับว่า เพีมตรงไหน  wanwan031
บันทึกการเข้า

รับเขียนบทความภาษาอังกฤษ ราคาถูก
1 คำ = 0.65 บาท
ขั้นต่ำ 100 คำ/บทความ
สนใจ PM มาได้
killer777
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 52
ออฟไลน์ ออฟไลน์

กระทู้: 1,009



ดูรายละเอียด เว็บไซต์
« ตอบ #4 เมื่อ: 27 สิงหาคม 2012, 12:54:02 »

wanwan023 เติม วัน+เวลา เข้าไปหลังชื่อ น่าจะโอเค นะครับ

ตามท่านนี้เลยครับ หรืออีกอย่างอาจจะ เพิ่ม md5 ด้วยครับ
บันทึกการเข้า

smapan
Global Moderator
เจ้าพ่อบอร์ดเสียว
*****

พลังน้ำใจ: 643
ออฟไลน์ ออฟไลน์

กระทู้: 8,272



ดูรายละเอียด เว็บไซต์
« ตอบ #5 เมื่อ: 27 สิงหาคม 2012, 12:55:58 »

md5 ข้อมูลในไฟล์ ครับเพื่อหา ใช้เป็น ID ของไฟล์นั้นๆ
บันทึกการเข้า

จูมล่าโฮส สยามโฮสเว็บ modty.com
รวมที่พัก เช่ารายวัน ที่พักเช่ารายเดือนมากที่สุดแจ่มจริง
***Tel 083-757-1515 ติดปัญหา Joomla ตรงไหนรับปรึกษาฟรี โทรมาเถอะครับ ถ้าตอบได้ช่วยแน่นอน ไม่มีกั้ก. ***
to2009
คนรักเสียว
*

พลังน้ำใจ: 40
ออฟไลน์ ออฟไลน์

กระทู้: 196



ดูรายละเอียด
« ตอบ #6 เมื่อ: 27 สิงหาคม 2012, 13:00:18 »

md5 ข้อมูลในไฟล์ ครับเพื่อหา ใช้เป็น ID ของไฟล์นั้นๆ
ขอตัวย่าง code ได้ใหมครับว่า เพีมตรงไหน
บันทึกการเข้า

รับเขียนบทความภาษาอังกฤษ ราคาถูก
1 คำ = 0.65 บาท
ขั้นต่ำ 100 คำ/บทความ
สนใจ PM มาได้
Basicman
คนรักเสียว
*

พลังน้ำใจ: 10
ออฟไลน์ ออฟไลน์

กระทู้: 178



ดูรายละเอียด
« ตอบ #7 เมื่อ: 27 สิงหาคม 2012, 13:05:01 »

ถ้าตามในโค้ด น่าจะประมาณนี้มั้งครับ

ไม่แน่ใจ ว่าถูกมั้ย นะ


โค๊ด:
<?php 
 
 
//This is the directory where images will be saved 
$time date"dmyHis" );
 
$target "images/"
 
$target $target basename$_FILES['photo']['name'].$time); 
 
 
//This gets all the other information from the form 
 
$name=$_POST['name']; 
 
$email=$_POST['email']; 
 
$phone=$_POST['phone']; 
 
$pic=($_FILES['photo']['name'].$time); 
 
 
// Connects to your Database 
 
mysql_connect("localhost""root""") or die(mysql_error()) ; 
 
mysql_select_db("Database_Name") or die(mysql_error()) ; 
 
 
//Writes the information to the database 
 
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; 
 
 
//Writes the photo to the server 
 
if(move_uploaded_file($_FILES['photo']['tmp_name'].$time$target)) 
 { 
 
 
//Tells you if its all ok 
 
echo "The file "basename$_FILES['uploadedfile']['name'].$time). " has been uploaded, and your information has been added to the directory"
 } 
 else { 
 
 
//Gives and error if its not 
 
echo "Sorry, there was a problem uploading your file."
 } 
 
?>

ผมต้องการที่จะป้องกันไม่ให้ชื่อภาพเในฐานข้อมูลขียนทับกันต้องทำไงครับ
ขอคําแนะนํา wanwan017 wanwan017
โค๊ด:
<?php 
 
 
//This is the directory where images will be saved 
 
$target "images/"
 
$target $target basename$_FILES['photo']['name']); 
 
 
//This gets all the other information from the form 
 
$name=$_POST['name']; 
 
$email=$_POST['email']; 
 
$phone=$_POST['phone']; 
 
$pic=($_FILES['photo']['name']); 
 
 
// Connects to your Database 
 
mysql_connect("localhost""root""") or die(mysql_error()) ; 
 
mysql_select_db("Database_Name") or die(mysql_error()) ; 
 
 
//Writes the information to the database 
 
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; 
 
 
//Writes the photo to the server 
 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
 { 
 
 
//Tells you if its all ok 
 
echo "The file "basename$_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"
 } 
 else { 
 
 
//Gives and error if its not 
 
echo "Sorry, there was a problem uploading your file."
 } 
 
?>
บันทึกการเข้า
smapan
Global Moderator
เจ้าพ่อบอร์ดเสียว
*****

พลังน้ำใจ: 643
ออฟไลน์ ออฟไลน์

กระทู้: 8,272



ดูรายละเอียด เว็บไซต์
« ตอบ #8 เมื่อ: 27 สิงหาคม 2012, 13:13:09 »

md5 ข้อมูลในไฟล์ ครับเพื่อหา ใช้เป็น ID ของไฟล์นั้นๆ

ขอตัวย่าง code ได้ใหมครับว่า เพีมตรงไหน


http://php.net/manual/en/function.md5-file.php

md5 ข้อมูลน่าจะมั่นใจได้ว่าไม่ซ้ำครับเพราะบางคนอัพไฟล์ชื่อซ้ำจริงแต่ ข้อมูลไม่ซ้ำครับ
โค๊ด:
<?php
$file 
= &#39;php-5.3.0alpha2-Win32-VC9-x64.zip&#39;;

echo &#39;MD5 file hash of &#39; . $file . &#39;: &#39; . md5_file($file);
?>
บันทึกการเข้า

จูมล่าโฮส สยามโฮสเว็บ modty.com
รวมที่พัก เช่ารายวัน ที่พักเช่ารายเดือนมากที่สุดแจ่มจริง
***Tel 083-757-1515 ติดปัญหา Joomla ตรงไหนรับปรึกษาฟรี โทรมาเถอะครับ ถ้าตอบได้ช่วยแน่นอน ไม่มีกั้ก. ***
to2009
คนรักเสียว
*

พลังน้ำใจ: 40
ออฟไลน์ ออฟไลน์

กระทู้: 196



ดูรายละเอียด
« ตอบ #9 เมื่อ: 27 สิงหาคม 2012, 13:59:16 »

ถ้าตามในโค้ด น่าจะประมาณนี้มั้งครับ

ไม่แน่ใจ ว่าถูกมั้ย นะ


โค๊ด:
<?php 
 
 
//This is the directory where images will be saved 
$time date"dmyHis" );
 
$target "images/"
 
$target $target basename$_FILES['photo']['name'].$time); 
 
 
//This gets all the other information from the form 
 
$name=$_POST['name']; 
 
$email=$_POST['email']; 
 
$phone=$_POST['phone']; 
 
$pic=($_FILES['photo']['name'].$time); 
 
 
// Connects to your Database 
 
mysql_connect("localhost""root""") or die(mysql_error()) ; 
 
mysql_select_db("Database_Name") or die(mysql_error()) ; 
 
 
//Writes the information to the database 
 
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; 
 
 
//Writes the photo to the server 
 
if(move_uploaded_file($_FILES['photo']['tmp_name'].$time$target)) 
 { 
 
 
//Tells you if its all ok 
 
echo "The file "basename$_FILES['uploadedfile']['name'].$time). " has been uploaded, and your information has been added to the directory"
 } 
 else { 
 
 
//Gives and error if its not 
 
echo "Sorry, there was a problem uploading your file."
 } 
 
?>

ผมต้องการที่จะป้องกันไม่ให้ชื่อภาพเในฐานข้อมูลขียนทับกันต้องทำไงครับ
ขอคําแนะนํา wanwan017 wanwan017
โค๊ด:
<?php 
 
 
//This is the directory where images will be saved 
 
$target "images/"
 
$target $target basename$_FILES['photo']['name']); 
 
 
//This gets all the other information from the form 
 
$name=$_POST['name']; 
 
$email=$_POST['email']; 
 
$phone=$_POST['phone']; 
 
$pic=($_FILES['photo']['name']); 
 
 
// Connects to your Database 
 
mysql_connect("localhost""root""") or die(mysql_error()) ; 
 
mysql_select_db("Database_Name") or die(mysql_error()) ; 
 
 
//Writes the information to the database 
 
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; 
 
 
//Writes the photo to the server 
 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
 { 
 
 
//Tells you if its all ok 
 
echo "The file "basename$_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"
 } 
 else { 
 
 
//Gives and error if its not 
 
echo "Sorry, there was a problem uploading your file."
 } 
 
?>

ได้แล้วนะครับ  thank q ทุกๆคำตอบเดี้  wanwan019 wanwan019
บันทึกการเข้า

รับเขียนบทความภาษาอังกฤษ ราคาถูก
1 คำ = 0.65 บาท
ขั้นต่ำ 100 คำ/บทความ
สนใจ PM มาได้
iLhay
Verified Seller
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 411
ออฟไลน์ ออฟไลน์

กระทู้: 4,368



ดูรายละเอียด เว็บไซต์
« ตอบ #10 เมื่อ: 27 สิงหาคม 2012, 14:42:52 »

ผมใช้ MD5 ตรวจการซ้ำของข้อมูล

แล้ว cache database สำหรับตรวจสอบ วันต่อวัน

ก็กรองซ้ำๆได้ระดับนึงนะ

แต่ไม่รุ้ว่า upic.me ของพี่ไอซ์กันไว้ยังไง   Embarrassed Embarrassed
บันทึกการเข้า

Wordpress Hosting


Wordpress Hosting เริ่มต้นปีละ 790 บาท NVMe SSD เร็ว 9000MB/s เร็วกว่านี้ไม่มีอีกแล้ว
Cloud Server เริ่มต้นเพียงเดือนละ 159 บาท พร้อมใช้ภายใน 1 นาที ผ่านระบบอัตโนมัติมีทั้ง Linux / Windows / DirectAdmin
สอบถามข้อมูลและแจ้งปัญหา 02-105-4417 ตลอด 24 ชั่วโมง
kanin03
สมุนแก๊งเสียว
*

พลังน้ำใจ: 53
ออฟไลน์ ออฟไลน์

กระทู้: 500



ดูรายละเอียด
« ตอบ #11 เมื่อ: 31 สิงหาคม 2012, 02:16:20 »

ผมใช้ MD5 ตรวจการซ้ำของข้อมูล

แล้ว cache database สำหรับตรวจสอบ วันต่อวัน

ก็กรองซ้ำๆได้ระดับนึงนะ

แต่ไม่รุ้ว่า upic.me ของพี่ไอซ์กันไว้ยังไง   Embarrassed Embarrassed

ตรงนี้คือ
อ้างถึง
ผมใช้ MD5 ตรวจการซ้ำของข้อมูล

คือพอมีการอัพโหลดไฟล์เข้ามา
ก็ไล่เชค md5 จากฐานข้อมูล ไล่ตาม id ไปจนอันสุดท้ายแบบนี้หรอครับ
แล้วถ้า id มันเยอะขึ้นมันจะช้าไหมอ่าครับ

ขอบคุณสำหรับคำแนะนำเรื่อง md5 ครับผมกำลังศึกษาการอัพโหลดไฟล์แบบนี้อยู่เหมือนกันครับ
 wanwan017
บันทึกการเข้า
jim_no1
สมุนแก๊งเสียว
*

พลังน้ำใจ: 19
ออฟไลน์ ออฟไลน์

กระทู้: 857



ดูรายละเอียด เว็บไซต์
« ตอบ #12 เมื่อ: 31 สิงหาคม 2012, 23:57:00 »

ต่องการทำให้เป็นแบบนี้หรือป่าวครับ
http://jimmodify.com
ลองเข้าไปดูก่อนนะครับ

- คลิ๊กที่ปุ่ม " เรียกดู "
- ปุ่ม " Submit "
แล้วระบบก็จะ Upload ภาพนั้นเข้าสู่ระบบน่ะครับ

แต่ว่า ของผมนั้น ได้ทำการย่อขนาดให้พอเหมาะกับหน้าเวปของเราด้วยน่ะครับ จะได้ไม่เกะกะมากเกินไป

ถ้าใช่แบบนี้ เดี๋ยวพรุ่งนี้ผมจะเข้ามาช่วยเหลืออีกครั้งนะครับ คืนนี้นอนก่อน ง่วงมาก ๆ แล้วล่ะ
บันทึกการเข้า

หน้า: [1]   ขึ้นบน
พิมพ์