I've got the following PHP code...
Which will return a file for downloading from a web site. The reason I have this code is because it's part of a secured area of the site. This is only included if the user has the correct credentials. I also have another secure area where admins can remotely upload the files to the web server. Butneither of these have anything to do with my problem, so I digress.
My problem is, sometime people upload .zip files (compressed with winZip) and they are usually excel files which are zipped. Now when the user downloads this file, it prompts them to save the zip file to their c:\ drive and then they need to "unzip" the file. The problem I have is that a lot of users don't know how to do that. (Don't laugh, I've tried online documentation and help but to no avail) So I get a lot (ok, not a lot but a few a week) emails asking me to unzip the file and email it to them.
Now, What I'd like to do is to have php automatically unzip the file before sending it back to the browser. Is that possible???
PHP Code:
<?php
//<!-- No index start 1 -->
include_once("../includes/dbConn.php");
if(isset($_GET['id'])) {
//id is set, include file
$id = $_GET['id'];
$sql = "SELECT fileType, fileName from fileTbl where metricID=".$id;
$rs = getDBData($sql);
$r = mssql_fetch_assoc($rs);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-type: ".$r['fileType']);
//name the download file $r['fileName']
$user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
if ((is_integer (strpos($user_agent, "msie"))) && (is_integer (strpos($user_agent, "win")))) {
header( "Content-Disposition: filename=".$r['fileName'].";" );
} else {
header( "Content-Disposition: attachment; filename=".$r['fileName'].";" );
}
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize("//domain/path/to/metrics/".$r['fileName']));
// The PDF source is in original.pdf
readfile('//domain/path/to/metrics/'.$r['fileName']);
mssql_free_result($rs);
}
else {
//no id set, display error
}
My problem is, sometime people upload .zip files (compressed with winZip) and they are usually excel files which are zipped. Now when the user downloads this file, it prompts them to save the zip file to their c:\ drive and then they need to "unzip" the file. The problem I have is that a lot of users don't know how to do that. (Don't laugh, I've tried online documentation and help but to no avail) So I get a lot (ok, not a lot but a few a week) emails asking me to unzip the file and email it to them.
Now, What I'd like to do is to have php automatically unzip the file before sending it back to the browser. Is that possible???
Comment