简体   繁体   中英

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
download button on selected content. Content can be (MP3,WAV,MP4,3gp,image). Content name is 9-digit random numeric character like 132432498.mp3 , 814274691.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 . I need help to write name of above content as I desire. How to do this in php?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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