This topic is locked

Zip and Download Selected

6/6/2024 7:51:51 PM
PHPRunner General questions
D
Dennis L author

I saw the youtube video, but I have a couple questions.

  • Do I use the name of the column that I store the link to the documents?
  • I am using Wasabi for storage of the uploaded files. Can I use Wasabi with this or do I need to the have files that I uploaded be on the server?
  • $filename = "templates_c/DownloadSelected".date("YmsHis").".zip"; How do I know what to put here? Do I use a folder on the server that allows uploads?

C
cristi 6/7/2024

1 - Yes
2. You can use other host as long as the links are public (so accesible to anyone) and the links in the column are direct download links: http://example.com/file.docx- for example
...and you need to modify the code in the video tutorial because that code is for locally hosted files....->look below for inspiration (only server code needs some changes):


$arrayf= array();
while($record = $button->getNextSelectedRecord())
{
$file=$record["direct_links_column"];

$arrayf[] = $file;

}
$zip = new ZipArchive();
$filename = "templates_c/ZipDocs".date("YmsHis").".zip";
$result["error"] = "";
$result["name"] = $filename;
if($zip->open(getabspath($filename), ZipArchive::CREATE)!==TRUE) {
$result["error"] = "Cannot create zip file";
}

foreach($arrayf as $fis)
{
$download_file = file_get_contents( $fis);
$zip->addFromString(basename($fis),$download_file);
}
  1. templates_c is automatically created by PHPRunner for temporary files when you export or import something, etc - from documentation: "Note: PHPRunner creates temporary files to preview the import results in the templates_c folder under the output directory. You need to set the writing permissions for this folder in the web server.?"

So, you need to give write permissions to that folder on the server, PHPRunner won't do that for you.

You should also think about implementing some kind of visual indicator that the download and zip of files is happening to your users....especially if the files are too many or large.