I am trying to modify a script to be able to select a directory from a list of directories, zip it, then download it.. so far, I haven't been successful.
here is the form which lists the directories:
This seems to work ok, and passes the directory name as 'file'; next:
So, after my modification, I get a file appropriatley name after the directory, but instead of the directory, I get an empty zip file. It should be noted the above script work perfectly when used as the author intended, but I need to be able to select a directory from a list, and the list is not static.
Here is the contents of the error log:
any help at fixing this mess would be appreciated.. I have tried all day, with many different combos, with no success.
Thanks!
here is the form which lists the directories:
Code:
<table width="541" border="0" align="center" bgcolor="#FFFF00">
<tr>
<td valign="middle" bgcolor="#FFFF00"><form action="getcustomerfiles.php" method="post"><div align="center"><span class="style26">Directory: </span><select name="file">
<? $folder = "../reseller/";
$handle = opendir($folder);
# Making an array containing the files in the current directory:
while ($file = readdir($handle))
{
$files[] = $file;
}
closedir($handle);
#echo the files
foreach ($files as $file) {
print "<option value=$folder$file>$file</option>";
}
?></select><input name="Get Directory" type="submit" value="Get Directory" /></div></form></td></tr></table>
This seems to work ok, and passes the directory name as 'file'; next:
Code:
<?PHP
@$directory = addslashes($_POST['file']);
// this script zips up a directory (on the fly) and delivers it
// C.Kaiser 2002
// No Copyright, free to use.
// get the filename of this php file without extension.
// that is also the directory to zip and the name of the
// zip file to deliver
// $filename_no_ext=str_replace(".php","",basename($SCRIPT_NAME));
$file =str_replace("../reseller/","",$directory);
// we deliver a zip file
header("Content-Type: archive/zip");
// filename for the browser to save the zip file
header("Content-Disposition: attachment; filename=$file".".zip");
// get a tmp name for the .zip
$tmp_zip = tempnam ("tmp", "tempname") . ".zip";
// zip the stuff (dir and all in there) into the tmp_zip file
`zip -r $tmp_zip $file`;
// calc the length of the zip. it is needed for the progress bar of the browser
$filesize = filesize($tmp_zip);
header("Content-Length: $filesize");
// deliver the zip file
$fp = fopen("$tmp_zip","r");
echo fpassthru($fp);
// clean up the tmp zip file
`rm $tmp_zip `;
?>
So, after my modification, I get a file appropriatley name after the directory, but instead of the directory, I get an empty zip file. It should be noted the above script work perfectly when used as the author intended, but I need to be able to select a directory from a list, and the list is not static.
Here is the contents of the error log:
Code:
[24-Apr-2007 19:15:17] PHP Warning: filesize(): Stat failed for /tmp/tempnameFF9AYc.zip (errno=2 - No such file or directory) in /home/xxx/public_html/admin/getcustomerfiles.php on line 27
[24-Apr-2007 19:15:17] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/public_html/admin/getcustomerfiles.php:27) in /home/xxx/public_html/admin/getcustomerfiles.php on line 28
[24-Apr-2007 19:15:17] PHP Warning: fopen(/tmp/tempnameFF9AYc.zip): failed to open stream: No such file or directory in /home/xxx/public_html/admin/getcustomerfiles.php on line 31
[24-Apr-2007 19:15:17] PHP Warning: fpassthru(): supplied argument is not a valid stream resource in /home/xxx/public_html/admin/getcustomerfiles.php on line 32
any help at fixing this mess would be appreciated.. I have tried all day, with many different combos, with no success.
Thanks!