glenelkins Posted February 27, 2006 Share Posted February 27, 2006 How would i let a user click a link and download a file in php. This can be any file type Link to comment https://forums.phpfreaks.com/topic/3663-download-with-code/ Share on other sites More sharing options...
tim_perrett Posted February 27, 2006 Share Posted February 27, 2006 Hi,try this... just set the content dispositsion and the file name etc[code]<?php function downloadFile($thefile, $ctype, $dname) { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-type: ".$ctype); header("Content-Length: ".filesize($thefile)); header("Content-Disposition: attachment; filename=\"".$dname."\""); header("Content-Transfer-Encoding: binary"); $fp = fopen($thefile); fpassthru($fp); fclose($fp); }$thefile = "HSC21.pdf";$ctype = "application/pdf";$dname = "HSC21.pdf";downloadFile($thefile, $ctype, $dname);?>[/code]CheersTim Perrett Link to comment https://forums.phpfreaks.com/topic/3663-download-with-code/#findComment-12692 Share on other sites More sharing options...
glenelkins Posted February 27, 2006 Author Share Posted February 27, 2006 ok cheers. is there a function to test a files extension? as i am wanting to allow downloads of multiple file types so:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$ctype = "application/pdf";[/quote]wot quite be good enough Link to comment https://forums.phpfreaks.com/topic/3663-download-with-code/#findComment-12695 Share on other sites More sharing options...
glenelkins Posted February 27, 2006 Author Share Posted February 27, 2006 for some reason its not working. i pass the correct file name but it just seems to only want to download user.php but without the extension Link to comment https://forums.phpfreaks.com/topic/3663-download-with-code/#findComment-12702 Share on other sites More sharing options...
tim_perrett Posted June 26, 2006 Share Posted June 26, 2006 im sure you can look at that code and mash somthing togehter to work out the content disposistion using the end(explode()) methods maybeIm not going to do it for you, thats not the name of game! lolTim Link to comment https://forums.phpfreaks.com/topic/3663-download-with-code/#findComment-49681 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.