chathura86 Posted December 9, 2008 Share Posted December 9, 2008 I want to make the download through the header commands. it is a txt file and i used header("Content-Disposition: attachment; filename=\"" . $myFile . "\""); readfile($myFile); but since i have other html codes below this line when i saved the file it also contains the html source also i want to show the html page while doing the downloading through header commands i have seen this in many sites like browser popups for the download but page displays with 'click here if your download does not start in few seconds' hope my question is clear Regards Link to comment https://forums.phpfreaks.com/topic/136230-solved-php-to-download-file-througe-header/ Share on other sites More sharing options...
rhodesa Posted December 9, 2008 Share Posted December 9, 2008 this isn't how they do it though. what they do is display the html page, then with a meta or javascript redirect, they point to the actual download link. since it's a forced download prompt, the html remains visible Link to comment https://forums.phpfreaks.com/topic/136230-solved-php-to-download-file-througe-header/#findComment-710727 Share on other sites More sharing options...
chathura86 Posted December 12, 2008 Author Share Posted December 12, 2008 can anyone show me an example how to do it Link to comment https://forums.phpfreaks.com/topic/136230-solved-php-to-download-file-througe-header/#findComment-713395 Share on other sites More sharing options...
ted_chou12 Posted December 12, 2008 Share Posted December 12, 2008 <?php // We'll be outputting a PDF header('Content-type: application/txt'); // It will be called downloaded.pdf header('Content-Disposition: attachment; filename="somefile.txt"'); // The PDF source is in original.pdf readfile('somefile.txt'); ?> dont forget to replace the somefile with ur own txt file name, Ted Link to comment https://forums.phpfreaks.com/topic/136230-solved-php-to-download-file-througe-header/#findComment-713409 Share on other sites More sharing options...
haku Posted December 12, 2008 Share Posted December 12, 2008 http://w-shadow.com/blog/2007/08/12/how-to-force-file-download-with-php/ Link to comment https://forums.phpfreaks.com/topic/136230-solved-php-to-download-file-througe-header/#findComment-713411 Share on other sites More sharing options...
chathura86 Posted December 12, 2008 Author Share Posted December 12, 2008 nope what i want is Display the HTML with while prompting the download http://www.filehippo.com/download_ccleaner/download/e70f585402395f82fa7a1cfd4f959582/ check this Link to comment https://forums.phpfreaks.com/topic/136230-solved-php-to-download-file-througe-header/#findComment-713417 Share on other sites More sharing options...
ted_chou12 Posted December 12, 2008 Share Posted December 12, 2008 After some investigation, i think this is done with javascript: http://tedchou12.110mb.com/uploads/phpforcedownload.php try if this is what u want Ted Link to comment https://forums.phpfreaks.com/topic/136230-solved-php-to-download-file-througe-header/#findComment-713428 Share on other sites More sharing options...
ted_chou12 Posted December 12, 2008 Share Posted December 12, 2008 this is the page u want html to store in: <?php echo "test";?> <script type="text/javascript"> <!-- window.location = "test.php" //--> </script> download page separate here: <?php header('Content-type: application/txt'); header('Content-Disposition: attachment; filename="3.txt"'); readfile('3.txt'); ?> Ted Link to comment https://forums.phpfreaks.com/topic/136230-solved-php-to-download-file-througe-header/#findComment-713429 Share on other sites More sharing options...
haku Posted December 12, 2008 Share Posted December 12, 2008 On html page: <a href="download.php?file=file.txt>Download</a> download.php: include(fileforce.php); // this is the file in the link I posted earlier set_time_limit(0); $file_path=$_GET['file']; $name = $_GET['file']; output_file($file_path, $name); Link to comment https://forums.phpfreaks.com/topic/136230-solved-php-to-download-file-througe-header/#findComment-713432 Share on other sites More sharing options...
chathura86 Posted December 12, 2008 Author Share Posted December 12, 2008 still you have to click on the link but on the sample url i posted earlier the download prompts automatically while the link is dispyed on the page Link to comment https://forums.phpfreaks.com/topic/136230-solved-php-to-download-file-througe-header/#findComment-713438 Share on other sites More sharing options...
haku Posted December 12, 2008 Share Posted December 12, 2008 So run the download script first, and at the end of it, have them forwarded to the html page, and add the link I gave you. Link to comment https://forums.phpfreaks.com/topic/136230-solved-php-to-download-file-througe-header/#findComment-713444 Share on other sites More sharing options...
rhodesa Posted December 12, 2008 Share Posted December 12, 2008 HTML PAGE Your download will begin shortly. If it does not start, click <a href="download.php">download</a>. <script type="text/javascript"> window.onload = function(){ window.location = 'download.php'; } </script> DOWNLOAD PAGE <?php header('Content-type: application/txt'); header('Content-Disposition: attachment; filename="file.txt"'); readfile('file.txt'); ?> Link to comment https://forums.phpfreaks.com/topic/136230-solved-php-to-download-file-througe-header/#findComment-713599 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.