Forum Moderators: coopster
$filename = 'afile.zip';
$ext = pathinfo($filename, PATHINFO_EXTENSION); <?php
$file_path = '/path/to/file/from/server/root.zip';
if(headers_sent()) {
die('Headers Sent');
}
if(ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
if(file_exists($file_path)) {
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="' . basename($file_path) . '";');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file_path));
ob_clean();
flush();
readfile($fullPath);
} else {
die('File Not Found');
}
?>
if(headers_sent()) {
die('Headers Sent');
}
<?php
//This page is for handling zip files only.
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
//not understood
if(headers_sent()) {
die('Headers Sent');
}
//make sure zlib.output_compression is off to allow output handlers
if(ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
// allow cache
header('Pragma: public');
//make permanent
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
// allow cache through proxy
header('Cache-Control: private', false);
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="' . basename($tempFile) . '";');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($tempFile));
ob_clean();
flush();
$fileTypes = str_replace('*.','',$_REQUEST['fileext']);
$fileTypes = str_replace(';','|',$fileTypes);
$typesArray = split('\|',$fileTypes);
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$typesArray)) {
move_uploaded_file($tempFile,$targetFile);
echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
} else {
echo 'Invalid file type.';
}
}
?>
if(headers_sent()) {
die('Headers Sent');
}
how did you get that box-effect around your code? It does make for easier reading.
[quote][pre]{code tags - break if I put them in here}[/pre][/quote]
I'm preparing an upload page where zipped files only should be uploaded.