Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

download directory and contents

Status
Not open for further replies.

kfelgner

Programmer
Mar 15, 2005
1
US
Any ideas on downloading an entire server directory and its files? I've been revising something like what follows - but it was planned to download each file one by one. Now, this isn't going to work.

Also, I was working with encoding my directory structure so that the server location and structure is hidden. I'd prefer to not have to zip the directory into one file - just another layer of complexity (unzip) for browsers.

<?
$file_dirr = $_POST['dirselect'];
if (!eregi("777",decoct(fileperms($file_dirr)))){
echo"<p align=\"center\" class=\"4x\">File Directory Not Found<p align=\"center\">";
}
else{
$opendir = @opendir($file_dirr);
while ($readdir = @readdir($opendir)){
if ($readdir<>"." && $readdir<>".." && $readdir != "index.html"){
$filearr[] = $readdir;
}
$sort=array();
for($i=1;$i<=count($filearr);$i++){
$key = sizeof($filearr)-$i;
$file = $filearr[$key];
$sort[$i]=$file;
}
asort($sort);
}
for($i=1;$i<=count($sort);$i++){
list($key,$x6y0z1)=each($sort);
if ($x6y0z1){
$x6y0z1_en = base64_encode($x6y0z1);
$x6y0z1x1y1z1=$x6y0z1;
}
$y9x4z3=str_replace('..','',base64_decode($x6y0z1x1y1z1));
$y1y7x0=$file_dirr."/".$y9x4z3;
$z5x3x2=$y9x4z3;
if (!file_exists($y1y7x0)) {
echo"Setup File Error - could not find";
exit();
}
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="'.$z5x3x2.'"');
header("Content-Length: ".filesize($y1y7x0));
header("Accept-Ranges: bytes");
header("Pragma: no-cache");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-transfer-encoding: binary");
@readfile($y1y7x0);
exit();
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top