Jump to content

trying to display html but headers are affecting it


adam291086

Recommended Posts

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

}
?>

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.

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."

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?

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?

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.