Hey,
I have this PHP script that takes files specified in an array and zips them to a zip file.
If you look near the bottom of the code, you'll see that there is an array like the following:
PHP Code:
$file_names=array('files/file1.mp3','files/file2.mp3','files/file3.mp3');
What I want to do is load the array from a text file that has data like this (instead loading the array by the method shown above):
Code:
path/to/file1.mp3
path/to/file2.mp3
path/to/file3.mp3
path/to/file4.mp3
I've tried some stuff but I can't figure out how to get this to work.
PHP Code:
<?php //function to zip and force download the files using PHP function zipFilesAndDownload($file_names,$archive_file_name,$file_path) { // Developed by Roshan Bhattarai // Visit http://roshanbh.com.np for this script and more. // This notice MUST stay intact for legal use
$zip = new ZipArchive(); //create the file and throw the error if unsuccessful if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) { exit("cannot open <$archive_file_name>\n"); } //add each files of $file_name array to archive foreach($file_names as $files) { $zip->addFile($file_path.$files,$files); } $zip->close(); //then send the headers to foce download the zip file header("Content-type: application/zip"); header("Content-Disposition: attachment; filename=$archive_file_name"); header("Pragma: no-cache"); header("Expires: 0"); readfile("$archive_file_name"); exit; } //example of using above function $file_names=array('files/file1.mp3','files/file2.mp3','files/file3.mp3'); $archive_file_name='zipped.zip'; $file_path=dirname(__FILE__).'/'; zipFilesAndDownload($file_names,$archive_file_name,$file_path); ?>
Thanks a million,
Moatist
__________________
Think in code; Dream in digital.
<?php if($helpfull == true){ $talkupation++; } ?>
Last edited by moatist; 07-15-2009 at 01:14 AM..
|