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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a .zip in php 4.3.2

Status
Not open for further replies.
Aug 23, 2004
174
US
This code works in PHP Version 5.2.3-1 but not 4.3.2. Can anyone point me in the right direction?

Code:
	if (file_exists('../podcast/download/'.$id.'.zip'))
		unlink('../podcast/download/'.$id.'.zip');

	$zip = new ZipArchive();
	$filename = "../podcast/download/".$id.".zip";

	if (($zip->open($filename, ZIPARCHIVE::CREATE)) !== TRUE) {
	    exit("cannot open <$filename>\n");
	}

	$zip->addFile("../podcast/".$name,$name);
	$zip->close();

Thanks
 
Thanks.

I got this working, kinda. I am having trouble adding files to the zip. I am using it to create zip files of mp3s for download. The zip file gets created but is empty.

Code:
	$zipname = "../podcast/download/".$id;
	$zipfile = "../podcast/".$name;

	exec("zip ".$zipname." ".$zipfile);
 
remember to change the working directory or be certain that you are using the right absolute/relative paths from where the script is being run.

and you might want to set the output parameter of the exec command so that you can debug.
Code:
$zipname = realpath("../podcast/download/$id);
$zipfile = realpath("../podcast/$name");
exec("zip $zipname $zipfile", $output);
echo "<pre>".print_r($output, true). "</pre>";
 
Thanks it works great. I had to use the absolute path for the file and I added -j to not include subdirectories.

Here is the final code:

Code:
$filename = "../podcast/download/".$id;
$file = ABS_PATH.$name;	//"../podcast/".$name;

exec("zip -j $filename $file");
 
realpath should have done the same (if the original path were correct). anyway, glad you've got it working. often it's easier to step outside of php and do things the old fashioned way. not to mention ... quicker!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top