jQuery จะ upload ไฟล์รูป ไปยังไงคะ??

เริ่มโดย nannkam, 01 มีนาคม 2015, 04:02:49

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

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

nannkam

หนูสร้าง form ให้กรอกข้อมูลต่างๆ แล้วใช้  $.post(url, $('form').serialize(), function(data) { 

แต่ไม่สามารถ upload ไฟล์รูปได้เลยค่ะ

ไม่ทราบว่า jQuery นี่จะ upload ไฟล์รูปไปอย่างไรคะ??? (งงทั้งวันเลยค่ะ)  :wanwan031:

goldxp

http://malsup.com/jquery/form/#file-upload

ajax ไม่มี upload file ครับ แต่มีวิธีอ้อมๆ อย่าง iframe
แล้วก็สมัยใหม่ html5 มีอะไรใหม่บ้างหรือเปล่าไม่แน่ใจครับ  :P
[direct=http://web-programming-bookmark.blogspot.com/p/blog-page.html]รับแก้ไขเว็บ[/direct]

zest_th

#2
ลองสร้าง php upload รูป ช่วยมั้ยครับ โดยส่ง url รูป ให้ jQuery แล้วเรียก php ให้ช่วยดูดรูปแทน
code ก็น่าจะประมาณนี้


       $ch = curl_init($source);
       $fp = fopen($output, 'wb');
       curl_setopt($ch, CURLOPT_FILE, $fp);
       curl_setopt($ch, CURLOPT_HEADER, 0);
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
       curl_exec($ch);
       curl_close($ch);
       fclose($fp);


ปล. code นี้ ดูดรูปได้จากทุกแหล่งครับ :)

nagis

ผมไม่ได้ใช้ jQuery นานแล้ว (ย้ายไป angular แล้ว)
แต่ถ้าถามว่าใช้ ajax upload file ได้ไหม ตอบว่าทำได้นะครับ อันนี้ตัวอย่าง
http://nervgh.github.io/pages/angular-file-upload/examples/without-bootstrap/

ส่วนวิธีทำอันนี้ต้องลองหาอ่านดู

goldxp

อ้างถึงจาก: nagis ใน 03 มีนาคม 2015, 05:48:33
ผมไม่ได้ใช้ jQuery นานแล้ว (ย้ายไป angular แล้ว)
แต่ถ้าถามว่าใช้ ajax upload file ได้ไหม ตอบว่าทำได้นะครับ อันนี้ตัวอย่าง
http://nervgh.github.io/pages/angular-file-upload/examples/without-bootstrap/

ส่วนวิธีทำอันนี้ต้องลองหาอ่านดู
ครับผม ตกข่าวไปนาน ช่วงแรกๆ ใช้ iframe หลอก เวอร์ชั่นใหม่ทำได้แล้ว :)
http://stackoverflow.com/questions/543926/is-it-possible-to-use-ajax-to-do-file-upload
[direct=http://web-programming-bookmark.blogspot.com/p/blog-page.html]รับแก้ไขเว็บ[/direct]