ขอถามเรื่อง php_upload_photo (+1 ทุกคำตอบ)

เริ่มโดย to2009, 27 สิงหาคม 2012, 12:41:14

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

to2009

ผมต้องการที่จะป้องกันไม่ให้ชื่อภาพเในฐานข้อมูลขียนทับกันต้องทำไงครับ
ขอคําแนะนํา :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

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

ccsakuna

อ้างถึงจาก: Basicman ใน 27 สิงหาคม 2012, 12:43:20
:wanwan023: เติม วัน+เวลา เข้าไปหลังชื่อ น่าจะโอเค นะครับ

ตามนั้น ไม่ซ้ำกันแน่นอนคะ
เว็บดูการ์ตูน ขายแบนเนอร์ 300 บาทต่อเดือน| [direct=http://www.cartoondek.com]ดูการ์ตูนออนไลน์[/direct] , [direct=http://www.ondims.com]สอนการตลาดออนไลน์[/direct] , [direct=http://www.dooconcert.com]ดูคอนเสิร์ตออนไลน์[/direct], [direct=http://www.pranui.com]ตลับพระ,ตลับเงินลงยา[/direct],
[direct=http://www.waxena.com]วาซีน่า ไวท์เทนนิ่ง[/direct],

to2009

อ้างถึงจาก: Basicman ใน 27 สิงหาคม 2012, 12:43:20
:wanwan023: เติม วัน+เวลา เข้าไปหลังชื่อ น่าจะโอเค นะครับ

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

killer777

อ้างถึงจาก: Basicman ใน 27 สิงหาคม 2012, 12:43:20
:wanwan023: เติม วัน+เวลา เข้าไปหลังชื่อ น่าจะโอเค นะครับ

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

smapan

md5 ข้อมูลในไฟล์ ครับเพื่อหา ใช้เป็น ID ของไฟล์นั้นๆ
[direct=http://cp.siamhostweb.com/cart.php?gid=1]จูมล่าโฮส สยามโฮสเว็บ[/direct] [direct=http://www.modty.com]modty.com[/direct]
[direct=http://www.apartment.in.th]รวมที่พัก เช่ารายวัน ที่พักเช่ารายเดือนมากที่สุดแจ่มจริง[/direct]
***Tel 083-757-1515 ติดปัญหา Joomla ตรงไหนรับปรึกษาฟรี โทรมาเถอะครับ ถ้าตอบได้ช่วยแน่นอน ไม่มีกั้ก. ***

to2009

อ้างถึงจาก: smapan ใน 27 สิงหาคม 2012, 12:55:58
md5 ข้อมูลในไฟล์ ครับเพื่อหา ใช้เป็น ID ของไฟล์นั้นๆ
ขอตัวย่าง code ได้ใหมครับว่า เพีมตรงไหน
รับเขียนบทความภาษาอังกฤษ ราคาถูก
1 คำ = 0.65 บาท
ขั้นต่ำ 100 คำ/บทความ
สนใจ PM มาได้

Basicman

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

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


<?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."
 } 
 
?>


อ้างถึงจาก: to2009 ใน 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."
 } 
 
?>


smapan

อ้างถึงจาก: to2009 ใน 27 สิงหาคม 2012, 13:00:18
อ้างถึงจาก: smapan ใน 27 สิงหาคม 2012, 12:55:58
md5 ข้อมูลในไฟล์ ครับเพื่อหา ใช้เป็น ID ของไฟล์นั้นๆ
ขอตัวย่าง code ได้ใหมครับว่า เพีมตรงไหน

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

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

echo 
'MD5 file hash of ' $file ': ' md5_file($file);
?>
[direct=http://cp.siamhostweb.com/cart.php?gid=1]จูมล่าโฮส สยามโฮสเว็บ[/direct] [direct=http://www.modty.com]modty.com[/direct]
[direct=http://www.apartment.in.th]รวมที่พัก เช่ารายวัน ที่พักเช่ารายเดือนมากที่สุดแจ่มจริง[/direct]
***Tel 083-757-1515 ติดปัญหา Joomla ตรงไหนรับปรึกษาฟรี โทรมาเถอะครับ ถ้าตอบได้ช่วยแน่นอน ไม่มีกั้ก. ***

to2009

อ้างถึงจาก: Basicman ใน 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."
 } 
 
?>


อ้างถึงจาก: to2009 ใน 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."
 } 
 
?>


ได้แล้วนะครับ  thank q ทุกๆคำตอบเดี้  :wanwan019: :wanwan019:
รับเขียนบทความภาษาอังกฤษ ราคาถูก
1 คำ = 0.65 บาท
ขั้นต่ำ 100 คำ/บทความ
สนใจ PM มาได้

iLhay

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

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

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

แต่ไม่รุ้ว่า upic.me ของพี่ไอซ์กันไว้ยังไง   :-[ :-[
[direct=https://bangmod.cloud/wordpress-hosting/]Wordpress Hosting

[/direct]
[direct=https://bangmod.cloud/wordpress-hosting/]Wordpress Hosting[/direct] เริ่มต้นปีละ 790 บาท NVMe SSD เร็ว 9000MB/s เร็วกว่านี้ไม่มีอีกแล้ว
[direct=https://bangmod.cloud/cloud-server]Cloud Server[/direct] เริ่มต้นเพียงเดือนละ 159 บาท พร้อมใช้ภายใน 1 นาที ผ่านระบบอัตโนมัติมีทั้ง Linux / Windows / DirectAdmin
สอบถามข้อมูลและแจ้งปัญหา 02-105-4417 ตลอด 24 ชั่วโมง

kanin03

อ้างถึงจาก: iLhay ใน 27 สิงหาคม 2012, 14:42:52
ผมใช้ MD5 ตรวจการซ้ำของข้อมูล

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

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

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

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

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

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

jim_no1

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

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

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

ถ้าใช่แบบนี้ เดี๋ยวพรุ่งนี้ผมจะเข้ามาช่วยเหลืออีกครั้งนะครับ คืนนี้นอนก่อน ง่วงมาก ๆ แล้วล่ะ
[direct=http://www.jimbeautify.com]jimbeautify.com ป้ายทะเบียนยาว[/direct]
[direct=http://jimbeautify.com/design/Plate_car/home_car.php]jimbeautify ออกแบบรถอย่างง่าย ๆ ด้วยตนเอง[/direct]
[direct=http://www.jimbeautify.com/forum/index.php] ประกาศขายสินค้าต่าง ๆ[/direct]
[direct=http://www.jimbeautify.com/forum/index.php?topic=15.0]คลิีกดูรายละเอียดเข้าร่วมฝึกอบรมทำป้ายทะเบียนกันน้ำแบบมืออาชีพ
[/direct]