blear Posted November 7, 2006 Share Posted November 7, 2006 Hey folks-I am attempting to implement a File Library section on my company's website. All filetypes not associated with web pages (.exe, .zip, etc) are downloaded by simply using JS to put the filename into a zero-size iframe, in order to abstract all of the operations of the site.The remaining file types (.php, .xml, etc) which are associated with web browsing do not work this way, as they are instead loaded as content in the zero-size iframe.I would like to know if there is a way to initiate a download of these files types without having to insruct the users to "Right click, then click save target as..." or anything other than "Click this link to begin the download of this file." Searching for a way to do this has proven quite difficult as the keyword "Download" makes any search useless for this purpose.Thank you all for any help you can give me. Link to comment https://forums.phpfreaks.com/topic/26479-initiate-download-of-xml-file/ Share on other sites More sharing options...
Orio Posted November 7, 2006 Share Posted November 7, 2006 I dont know much about this topic, but I know what you are looking for is called "force download".By googling I found [url=http://lists.evolt.org/archive/Week-of-Mon-20050214/169427.html]this[/url] page, that said this is the way to force downlaod-[code]<?phpheader( "Content-Type: application/octet-stream" );header( "Content-Length:" . filesize( $filepath ) );header( "Content-Disposition: attatchment; filename=$filename" );readfile( $filepath );?>[/code]You can find your own explaintions/tutorials tho by searching the term "force download".Orio. Link to comment https://forums.phpfreaks.com/topic/26479-initiate-download-of-xml-file/#findComment-121136 Share on other sites More sharing options...
blear Posted November 7, 2006 Author Share Posted November 7, 2006 Thanks a bunch Orio. Your code helped me into the right direction, the search topic was the icing.This button:[code] <A CLASS = 'fileButton' href='javascript:Download(\"$userFile\",$version);'>$userFile</A> [/code]called this js function[code]function Download(fileName,version){ userID = window.parent.parent.document.forms[0].elements['userID'].value; filePath = "fileLibrary/" + version + "/"; window.frames[0].location.replace('downloader.php?userID=' + userID + '&path='+ filePath + '&file=' + fileName);};[/code]Which activated the download with this code in downloader.php:[code] {removed authentication script}$filePath=$_REQUEST['path'];$fileName=$_REQUEST['file'];$full = $filePath.$fileName;Header( "Content-Length:" . filesize( $full ) );Header( "Content-Type: application/octet-stream" );Header( "Content-Disposition: attatchment; filename=$fileName" );readfile( $full );[/code]Thanks again. Link to comment https://forums.phpfreaks.com/topic/26479-initiate-download-of-xml-file/#findComment-121168 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.