Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > พี่ ๆ ดูให้หน่อยค่ะ เขียนโค้ดดาวน์โหลดอย่างงี้มันไม่ได้อ่ะค่ะ



 

พี่ ๆ ดูให้หน่อยค่ะ เขียนโค้ดดาวน์โหลดอย่างงี้มันไม่ได้อ่ะค่ะ

 



Topic : 047699

Guest




พี่ ๆ ดูให้หน่อยค่ะ เขียนโค้ดดาวน์โหลดอย่างงี้มันไม่ได้อ่ะค่ะ

Code (PHP)
<?php
// downloading a file
$filename = $_GET['C:\AppServ\www\test\upload\01082010674.jpg']; ###แก้ที่เก็บไฟล์###


// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache


// force download dialog
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");


// use the Content-Disposition header to supply a recommended filename and
// force the browser to display the save dialog.
header("Content-Disposition: attachment; filename=".basename($filename).";");


/*
21.The Content-transfer-encoding header should be binary, since the file will be read
22.directly from the disk and the raw bytes passed to the downloading computer.
23.The Content-length header is useful to set for downloads. The browser will be able to
24.show a progress meter as a file downloads. The content-lenght can be determines by
25.filesize function returns the size of a file.
26.*/
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));


@readfile($filename);
exit(0);
?>




Tag : PHP, Ms SQL Server 2005







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-08-26 11:26:22 By : Nutty View : 1163 Reply : 12
 

 

No. 1



โพสกระทู้ ( 1,579 )
บทความ ( 3 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


เข้าไปอ่านในนี้นะครับ ป๋าอั้น ทำไว้ให้แล้ว
https://www.thaicreate.com/php/forum/032323.html
อยู่ NO. 86






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-26 11:30:57 By : somparn
 


 

No. 2

Guest


ยังไม่ได้อยู่ดีค่ะ

Code (PHP)
<?
<font class="detailDesc"><font class="css_code">$file = "upload/ACS_brochure.pdf";    //ตรงนี้แก้เป็นที่อยู่ไฟล์ใช่มั้ยคะ   line 2
header("Cache-Control: public");             
header("Content-Type: application/pdf");
header("Content-Description: File Transfer");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=" . $file);
header("Content-Length: " . filesize($file));
readfile($file);
</font></font>
?>


ขึ้น error ว่า

Parse error: syntax error, unexpected '<' in C:\AppServ\www\test\Untitled-1.php on line 2


ขอบคุณนะคะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-26 11:49:17 By : Nutty
 

 

No. 3

Guest


Code (PHP)
	if($download_file)
		header("Pragma: public");
		header("Expires: 0"); 
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
		header("Content-Type: application/force-download");
		header("Content-Type: application/octet-stream");
		header("Content-Type: application/download");
		header("Content-Disposition: attachment; filename=".basename($download_file).";");
		header("Content-Transfer-Encoding: binary");
		header("Content-Length: ".filesize($download_file));
		@readfile(($download_file)); 
		
	}

<a href="?download_file=upload/ACS_brochure.pdf">download</a>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-26 12:38:43 By : heng
 


 

No. 4

Guest


ทำไมหนูเอาคำสั่งดาวน์โหลดไปไว้ใน while มันไม่ขึ้น popup ดาวน์โหลดให้คะ มันแค่เข้าไปที่อยู่ของไฟล์อ่ะคะ

Code (PHP)
$sql="select*from upload where type='$jpg'";
$result=mssql_query($sql);
while($row=mssql_fetch_row($result)){


if($download_file)
		{header("Pragma: public");
		header("Expires: 0"); 
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
		header("Content-Type: application/force-download");
		header("Content-Type: application/octet-stream");
		header("Content-Type: application/download");
		header("Content-Disposition: attachment; filename=".basename($download_file).";");
		header("Content-Transfer-Encoding: binary");
		header("Content-Length: ".filesize($download_file));
		@readfile(($download_file)); 
		
	}

echo"<a href='?download_file=upload/$row[3]'>download</a>";            // $row[3] คือชื่อไฟล์ค่ะ
}


ผลลพัธ์ว่า

http://localhost/test/download.php?download_file=upload/26703_407839104005_660589005_4671444_6438442_n.jpg

งี้อ่ะค่ะตรง browser ie มันขึ้นงี้ก็แสดงว่ามันเข้าถึงไฟล์แล้ว แต่ทำไมมันไม่ขึ้น popup ดาวน์โหลดคะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-26 13:28:02 By : Nutty
 


 

No. 5

Guest


รออยู่นะึคะ

ขอบคุณคะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-26 14:10:40 By : Nutty
 


 

No. 6

Guest


เอาทั้งหมดไว้นอก while นะ เอาไว้บรรทัดบนสุดด้วย
Code (PHP)
<?
if($download_file)
		{header("Pragma: public");
		header("Expires: 0"); 
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
		header("Content-Type: application/force-download");
		header("Content-Type: application/octet-stream");
		header("Content-Type: application/download");
		header("Content-Disposition: attachment; filename=".basename($download_file).";");
		header("Content-Transfer-Encoding: binary");
		header("Content-Length: ".filesize($download_file));
		@readfile(($download_file)); 
		
	}
?>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-26 15:09:58 By : heng
 


 

No. 7

Guest


ไม่มีวิธีอื่นเหรอคะ ไว้นอกลูปมันก็ขึ้นดาวน์โหลดแค่ไฟล์เดียว ไฟล์อื่นก็ไม่ขึ้น
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-26 16:16:56 By : Nutty
 


 

No. 8

Guest


ลองแล้วลองอีก .... ยังรอต่อไป
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-26 18:20:26 By : Nutty
 


 

No. 9

Guest


ถามได้นะคะ คือมีไฟล์ให้ดาวน์โหลดหลายไฟล์อ่ะค่ะ แล้วตัวแปร row[3] คือชื่อไฟล์ พอใส่ $row[3] ต่อท้าย upload มันก็จะเข้าไปถึงไฟล์

นั้น ๆ อ่ะค่ะ ถ้าใส่ไว้นอกลูป while มันก็จะแสดงดาวน์โหลดอันเดียวใช่มั้ยคะ ไม่แสดงให้ทุกดาวน์โหลดทุกไฟล์ ปัญหาคือตรงนี้อ่ะค่ะ ทำไง

ให้มันขึ้นว่าดาวน์โหลดทุกไฟล์ พอจะมีวิธีอื่นมั้ยคะ มือใหม่จริง ๆ ค่ะ

ขอบคุณค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-26 19:29:50 By : Nutty
 


 

No. 10

Guest


ช่วยแนะหน่อยค่ะ ทั้งวันแล้ว ตันจริง ๆ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-26 23:38:54 By : Nutty
 


 

No. 11

Guest


เวลาดาวน์โหลด ต้องกดปุ่ม download ก่อนหรือเปล่า ถ้าใช่เขียนตามนี้
Code (PHP)
<?
if($download_file)//เอาไว้บรรทัดบนสุด
{
	header("Pragma: public");
	header("Expires: 0"); 
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
	header("Content-Type: application/force-download");
	header("Content-Type: application/octet-stream");
	header("Content-Type: application/download");
	header("Content-Disposition: attachment; filename=".basename($download_file).";");
	header("Content-Transfer-Encoding: binary");
	header("Content-Length: ".filesize($download_file));
	@readfile(($download_file)); 
		
}

$sql="select*from upload where type='$jpg'";
$result=mssql_query($sql);
while($row=mssql_fetch_row($result)){

echo "<a href='?download_file=upload/$row[3]'>download</a>";  
echo "<br>";          

}

?>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-27 12:52:53 By : heng
 


 

No. 12



โพสกระทู้ ( 1,268 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Blogger

แยกเป็นดาวน์โหลดทีละไฟล์ไหมคะ ถ้าต้องการดาวน์โหลดทั้งหมดก็ทำเป็น zip file แบบนี้จะดีไหม
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-27 14:54:01 By : ultrasiam
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : พี่ ๆ ดูให้หน่อยค่ะ เขียนโค้ดดาวน์โหลดอย่างงี้มันไม่ได้อ่ะค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่