Jump to content

PHP Zip creating grief


primetechv2

Recommended Posts

I want to take an array of files, retrieve them via CURL, and then compress them into a ZIP archive. Unfortunately, PHP has different plans and creates zip files that are unreadable.

 

$files = $_POST['files'];
$files = explode( "\n" , $files );

$zip = new ZipArchive();
$filename = "./test112.zip";
unlink($filename);		// delete it


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

for ($i = 0; $i < sizeOf($files); $i++)
{
$files[$i] = str_replace( "\l", "", $files[$i] );
$files[$i] = str_replace( "\n", "", $files[$i] );
$files[$i] = str_replace( "\r", "", $files[$i] );
$files[$i] = str_replace( " ", "", $files[$i] );
if ($files[$i] != "") {
	echo "Adding " . $files[$i] . "<br>\n";
	$out = geturl( $files[$i] );
//		$addfile = fopen("$i.tmp",'w');
//		fwrite($addfile, $out);
//		fclose($addfile);
	$zip->addFromString("$i.tmp",$out);

	//echo "<textarea cols=30 rows=20>" . $out . "</textarea><br>\n";
}
}

Link to comment
https://forums.phpfreaks.com/topic/104733-php-zip-creating-grief/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.