ติดปัญหา download รูปภาพ

สำหรับผู้ที่ เริ่มต้น Programming - PHP มีอะไร แนะนำ หรือข้อสงสัยต้องบอร์ด นี้ คนที่มีความรู้ แบ่งปันคนอื่นบ้างนะ ปัญหาการเขียนโปรแกรม แบบ OOP Session Cookies php network

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
eange08
PHP VIP Members
PHP VIP Members
โพสต์: 16184
ลงทะเบียนเมื่อ: 22/12/2020 10:09 am

ติดปัญหา download รูปภาพ

โพสต์ที่ยังไม่ได้อ่าน โดย eange08 »

กด download ภาพที่เรียกจากใน folder พอกดแล้วดันไปหน้าเพจขาว ไม่มีไฟล์ download ลงมาจะต้องแก้ไขยังงัยบ้างค่ะ
เพราะเปิดสิทธิโฟลเดอร์ uploads/before กับตัวรูปแล้วนะคะ
Screenshot from 2021-01-06 16-36-18.png
ส่วนของ code ค่ะ

โค้ด: เลือกทั้งหมด

$file = 'Manual-Crop.jpg';

if (file_exists($file)) {
    header ('Content-Type: image/jpeg');
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));

    ob_clean();
            flush();
readfile('/uploads/before/'.$file);
            exit;
}
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41232
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: ติดปัญหา download รูปภาพ

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

file_exists ที่ เช็ค path ที่เช็ค กับ path ที่อ่านไฟล์ มาใช้ คนละ path กันอยู่ ครับ

โค้ด: เลือกทั้งหมด

if (file_exists($file)) 
***

โค้ด: เลือกทั้งหมด

readfile('/uploads/before/'.$file);
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ภาพประจำตัวสมาชิก
eange08
PHP VIP Members
PHP VIP Members
โพสต์: 16184
ลงทะเบียนเมื่อ: 22/12/2020 10:09 am

Re: ติดปัญหา download รูปภาพ

โพสต์ที่ยังไม่ได้อ่าน โดย eange08 »

mindphp เขียน: 06/01/2021 5:17 pm file_exists ที่ เช็ค path ที่เช็ค กับ path ที่อ่านไฟล์ มาใช้ คนละ path กันอยู่ ครับ

โค้ด: เลือกทั้งหมด

if (file_exists($file)) 
***

โค้ด: เลือกทั้งหมด

readfile('/uploads/before/'.$file);
แก้ใส่ path ที่ตัวแปร $file ไปเรียกใหม่ก็ download ไฟล์ได้แล้วนะคะ

โค้ด: เลือกทั้งหมด

$file = dirname(__FILE__) . '/uploads/before/test.png';

header("Pragma: no-cache");
header("Expires: 0");
header("Content-Type: image/png");
 header('Content-Disposition: attachment; filename="'.basename($file).'"');
header("Content-Transfer-Encoding: binary");
header('Content-Length: ' . filesize($file));
echo file_get_contents($file);

exit;
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 111