adam291086 Posted September 2, 2008 Share Posted September 2, 2008 I am forcing a download and therefore the headers need to be set before anything else. Otherwise the file wont download it just displays loads of jargen. I want to be able to display some html saying file downloaded. Heres the code below else { $messgae = 'Download Successful'; // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // addition by Jorg Weske $file_extension = strtolower(substr(strrchr($filename,"."),1)); if( $filename == "" ) { echo "<html><title>eLouai's Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>"; exit; } elseif ( ! file_exists( $filename ) ) { echo "<html><title>eLouai's Download Script</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>"; exit; }; switch( $file_extension ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: $ctype"); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Folder Name</title> <link href="/admin/FTP/css/foldername-style.css" rel="stylesheet" type="text/css" /> <script> var howLong = 3000; t = null; function closeMe(x){ window.opener.location.href = window.opener.location.href; t = setTimeout("self.close()",howLong); } </script> </head> <body class="body" bgcolor="#ffffff" onload="closeMe();self.focus()"><div align="center"> <div id="centered"><table width="439" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="2"><img src="/admin/FTP/images/foldername_01.png" /></td> </tr> <tr> <td><img src="/admin/FTP/images/foldername_02.png" alt="Folder Name" /></td> <td><a href="javascript:window.close()"><img src="/admin/FTP/images/foldername_03.png" alt="close" border="0"/></a></td> </tr> <tr> <td id="padding" height="99" colspan="2" background="/admin/FTP/images/foldername_04.png"> <div id="text_success" class="text_success" align="center" valign="middle"> <?php echo $message;?> </div></td> </tr> <tr> <td><img src="/admin/FTP/images/foldername_05.png" /></td> </tr> </table></div></form> </body> </html> <?php } ?> Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 2, 2008 Author Share Posted September 2, 2008 still not working, anyone? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 2, 2008 Author Share Posted September 2, 2008 sorry to bump but i have been playing with is all afternoon and still no luck Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted September 2, 2008 Share Posted September 2, 2008 So if its a valid file to be downloaded what happens? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 2, 2008 Author Share Posted September 2, 2008 if its a valid file the file is downloaded and i want the screen to say download sucessful. Which is the html code below the php force download. If i put the html above the headers the file isnt downloaded, just prints jargen representing the file to the screen. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 2, 2008 Share Posted September 2, 2008 you can't do this with just PHP. "maybe" with Javascript added in.... you send a header saying "here is a file. download it." you can't then send another header that says "display HTML that says 'Download complete.'" i would follow an example used on many sites that says something like "thank you for downloading whatever. if your download doesn't begin within 5 seonds, click here." Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 2, 2008 Author Share Posted September 2, 2008 well how it works is like this the user selects a file and clicks the download button. Then javascript opens a popup window that will display either file not found or please select a file. If the file is there and it is a file then download. After the download script should i have header(location:"http://dfhdsfkhdskf.com"); to display the download complete? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 2, 2008 Share Posted September 2, 2008 i understand what you're trying to do. and you can't do that. you are trying to send headers after the download already started, and you can't do that. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 2, 2008 Author Share Posted September 2, 2008 so i should check the file is present and the file is a file and then send a header to a download script and have a pop window saying download complete Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 2, 2008 Share Posted September 2, 2008 i would follow an example used on many sites that says something like "thank you for downloading whatever. if your download doesn't begin within 5 seonds, click here." i can't think of a way to tell when a download is complete. can you? Quote Link to comment Share on other sites More sharing options...
discomatt Posted September 2, 2008 Share Posted September 2, 2008 i would follow an example used on many sites that says something like "thank you for downloading whatever. if your download doesn't begin within 5 seonds, click here." i can't think of a way to tell when a download is complete. can you? Nothing in PHP alone, no. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 2, 2008 Share Posted September 2, 2008 right. i mean, the browser knows the download is complete and should tell the user. why does php also need to tell the user the download is complete? there are some java-based downloaders out there that will display the total amount downloaded and tell the user when downloads are complete. but for my time (= money), i'll let the browser tell them. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.