Using PHP to create custom zip files for site visitors

sonofsky

New Member
Messages
1
Reaction score
0
Points
0
I'm going to try to explain this a simply as possible. I am an Android developer, and what I want to do is related to that, but you don't have to understand Android to be able to help out.

I want to create a website where someone can create their own custom version of android operating system for their phone/tablet from a list of choices. I want them to select a device, choose things like Launcher/Clock/Theme etc. from dropdown boxes, select checkboxes for additional applications, and then the site will build a flashable .zip file using the selected components.

I will have a clean base file for each device, as well as all the optional components, but i need code to create a copy of that base, rename it based on the username of the creator, and add all of the selected files into the copy. the site will then direct the user to a download link for that file, and after the download is complete (maybe wait an extra hour or so in case they need to redownload) it will delete this custom file.

I found this site (http://us2.php.net/manual/en/ziparchive.addfile.php) which gives some basic instructions on modifying a zip file, how could this be modified to add files based on peoples selections on the site?

the files i need to add would be a few directories deep inside the .zip if that makes a difference.

I can upload an example .zip file if necessary.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Your description is too open-ended. What, exactly, is the issue? Where are you stuck? The documentation has the basic information: copying files, renaming files, manipulating ZIP archives, sending HTTP headers to redirect. To run PHP scripts not in response to an HTTP request, you need to set up a cron job; alternatively, have the PHP script that constructs the ZIP archive output it instead of redirecting to the file, then delete the file at the end of the script. For performance's sake, you can always create a caching mechanism for generated archives.
 
Last edited:

enox10mx

New Member
Messages
29
Reaction score
0
Points
0
here is an example solution, where I use the function multiple times with IF functions:
PHP:
$option1 = $_get['option1']; $option2 = $_get['option2'];   $option3 = $_get['option4'];  if($option1 == yes)  { create_zip('file1.php,'my-archive.zip');   } if($option2 == yes)  {  create_zip('file2.php','my-archive.zip');  }  if($option3 == yes) {create_zip('file3.php','my-archive.zip');  }
You must include the function before this, I did not want to include that. You also might want to capitalize the 'get' part so it says 'GET', I am not sure if that matters.
 

adam.k

New Member
Messages
41
Reaction score
1
Points
0
Yes, it does have to be 'GET' not 'get'. PHP is a case-sensitive language.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Some things in PHP (e.g. constants, variable names (which includes properties)) are case sensitive, but others aren't (e.g. functions, which includes methods).

@enox10mx: please pick and apply an indent style when posting code to make it readable. Also, make sure your samples don't have syntax errors. You can preview your message and check the coloration to find errors. You keep using "yes" as a bareword; don't. Undeclared constants are considered bad practice, which is why they generate warning notices. If you want to use "yes" as a constant, make sure you explicitly define it as such. The sample code doesn't appear to address what little the OP has specified, but (as create_zip isn't a standard PHP function) there's no way to evaluate it for sure. The approach isn't very scalable, requiring each file to be processed separately.
 
Top