tsclan
10-23-2005, 01:25 AM
I made a script that will upload a .zip file and rename it based on the id of the information that was inserted into a database. All works fine, except most of the files when you download them they say they are corrupted, yet you can extract them and everything works fine. Any ideas on why it would say it was corrupted..
here is code...
upload
foreach($_FILES as $file_name => $file_array) {
$ext = explode(".", $file_array['name']);
$ext1 = $ext[1];
if ($ext1 == "zip") {
if ($file_array['size'] < $maxzip) {
move_uploaded_file($file_array['tmp_name'],$template_dir . $id.".".$ext1);
} else {
$temp->assign('error', "Zip Files Must Not Exceed 5 MegaBytes!");
$temp->display('error.tpl');
$temp->display('submit_templates.tpl');
exit();
}
} else {
move_uploaded_file($file_array['tmp_name'],$thumbnail_dir . $id.".".$ext1);
}
download
$filename = $template_dir . $file."."."zip";
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache
// force download dialog
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename($filename).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
here is code...
upload
foreach($_FILES as $file_name => $file_array) {
$ext = explode(".", $file_array['name']);
$ext1 = $ext[1];
if ($ext1 == "zip") {
if ($file_array['size'] < $maxzip) {
move_uploaded_file($file_array['tmp_name'],$template_dir . $id.".".$ext1);
} else {
$temp->assign('error', "Zip Files Must Not Exceed 5 MegaBytes!");
$temp->display('error.tpl');
$temp->display('submit_templates.tpl');
exit();
}
} else {
move_uploaded_file($file_array['tmp_name'],$thumbnail_dir . $id.".".$ext1);
}
download
$filename = $template_dir . $file."."."zip";
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache
// force download dialog
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename($filename).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");