I was wondering if it was possible to upload say a picture file and a text file and in the script put them into a zip file programatically.

if this is possible could you offer some tips or links please?

regards!

Thank you it looks like ill be reading for a while.
thanks again ,regards

This tells you everything you need to know about zipping with PHP.

http://us3.php.net/zip

Here is an upload tutorial you may find helpful.

http://www.tizag.com/phpT/fileupload.php

You'll have to create a file specific to the user, then add the two files, and finally send it to zip.


Good luck!

ok so to do a zip file through php. correct me if im wrong.

i use fopen to create a zip archive
fclose to close it
then use the ziparchive class to open it again
then use the addfile function to add a file to the archive.
then use close

but anywho, im getting an error when i try to unzip the folder, it is
0x80004005

any idea why this is?

ahh i c, sorry about that. so what should i do? keep posting here? or there.

anyways....my code

if(isset($_POST['upload'])){

$zip_dir = 'packs/zips/';
$license = $_POST['license'];
$title = $_POST['title'];
$title .= '_' . rand(999999,time()) . '.zip';
echo $title;

$zip = new ZipArchive;
$pack = fopen($zip_dir.$title,'wb');
fclose($pack);
$zip->open($zip_dir.$title);
$zip->addFile($license, 'newfile.txt');
$zip->close();
}
?>

<form enctype="multipart/form-data" action="" method="post">
<?php if(file_exists('License.txt'))
{
	$combo = '<select name="license">';
	$combo .= '<option value="License.txt">License</option>';
	$combo .= '</select>';
	echo $combo;	
} 
?>

This tells you everything you need to know about zipping with PHP.

http://us3.php.net/zip

Here is an upload tutorial you may find helpful.

http://www.tizag.com/phpT/fileupload.php

You'll have to create a file specific to the user, then add the two files, and finally send it to zip.


Good luck!

I was wondering if it was possible to upload say a picture file and a text file and in the script put them into a zip file programatically.

if this is possible could you offer some tips or links please?

regards!

Wouldn't it be a good idea to re-use your previous thread which is still on the front page.

And if you post your code then people may be able to point out where you are going wrong.

Although, this is the example given by php.net:

<?php
$zip = new ZipArchive();
$filename = "./test112.zip";

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

$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile($thisdir . "/too.php","/testfromfile.php");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
?>

Ok, my apologies, I tried to merge these two threads and it came out a bit of a mess. Hopefully something relevant can still be salvaged.

Ok, my apologies, I tried to merge these two threads and it came out a bit of a mess. Hopefully something relevant can still be salvaged.

yeah i see that. oh well.

i have attached my error as an image.

and here is my code.

<?php

if(isset($_POST['upload'])){

	$zip_dir = 'packs/zips/';
	$license = $_POST['license'];
	$title = $_POST['title'];
	$title .= '_' . rand(999999,time()) . '.zip';
	echo $title;

	$zip = new ZipArchive;
	if(!$zip->open($zip_dir.$title, ZIPARCHIVE::CREATE))
	{
		echo 'Couldnt creat file';
	}else
	{
		$zip->addFile($license, 'newfile.txt');
		$zip->close();	
	}
}
?>

<form enctype="multipart/form-data" action="" method="post">
<?php if(file_exists('License.txt'))
{
	$combo = '<select name="license">';
	$combo .= '<option value="License.txt">License</option>';
	$combo .= '</select>';
	echo $combo;	
} 
?>
Title<input type="text" name="title"/>
image:<input type="file" name="img" />
<input type="submit" name="upload" value="upload" onclick="javascript:self.location.reload();" />



</form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.