I’ve php script for creating zip folder of some text files
<?php
$path = "path\to\files";
$files = array($path.'\ionic interaction.txt',$path.'\file1.txt',$path.'\file2.txt',$path.'\file3.txt',$path.'\file3.txt');
$folder = $_POST['filename'];
$zipname = $folder.'.zip';
echo '<form action="download.php" method="post" name="zippass2download"><input type="hidden" name="zipname" value="'.$zipname.'"></form>';
$zip = new ZipArchive;
$zip -> open($zipname, ZipArchive::CREATE);
foreach($files as $file)
{
$zip -> addFile($file);
}
$zip -> close();
?>
Next to that script I’ve created a hyperlink to download the zip folder created in the first script.
<a href="download.php">Download</a>
In download.php I’ve following codes
<?php
$path2zip = 'C:/wamp/www/PPInt';
$tobezipped = $_POST['zipname'];
header('Content-disposition: attachment; filename=$tobezipped');
header('Content-type: application/zip');
readfile('$path2zip/$tobezipped');
?>
Not getting where is the problem. Can anyone solve this for me?
$tobezipped = $_POST[‘zipname’];
is not set in the get request that is made when download.php is called. Rember HTTP is stateless so, after you generate the file. POST params don’t live in the next GET request when the link is clicked.
You probably need to append the zipname / path to your download.php link as in “download.php?tobezipped=zipname.zip”