简体   繁体   English

如何通过单击php中的下载按钮来给出保存对话框?

[英]How to give save dialog box by clicking on download button in php?

I am working on content based WAP application in which I will have to put 我正在研究基于内容的WAP应用程序,我必须将其放在其中
download button on selected content. 所选内容上的下载按钮。 Content can be (MP3,WAV,MP4,3gp,image). 内容可以是(MP3,WAV,MP4、3gp,图像)。 Content name is 9-digit random numeric character like 132432498.mp3 , 814274691.mp4 . 内容名称是9位数的随机数字字符像132432498.mp3814274691.mp4 I tried below code 我尝试下面的代码

 <?php if(isset($_GET['fileId'])){  
$fileid = $_GET['fileId'];  
{   
i retrieve content content path and name together 
like $filename="myserverip/1/3/4/132432498.mp3"   
}   
then  
header ("Content-type: octet/stream");   
header ("Content-disposition: attachment; filename=".$filename.";");    
header("Content-Length: ".filesize($filename));     
 readfile($filename);       
exit;
?>   
< a  href= < ? php echo $filename; ?>>Download < /a> '

But file automatically gets downloading with name 132432498.mp3 . 但是文件会自动以132432498.mp3名称下载。 I need help to write name of above content as I desire. 我需要我帮忙写以上内容的名称。 How to do this in php? 如何在php中做到这一点?

可能是因为您提供的名称带有空格,因此必须避免用双引号将其引起来,如下所示:

header('Content-Disposition: attachment; filename="'.$filename.'"');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM