Results 1 to 5 of 5

Thread: Using PHP to create custom zip files for site visitors

  1. #1
    sonofsky is offline x10Hosting Member
    Join Date
    Mar 2012
    Posts
    1

    Using PHP to create custom zip files for site visitors

    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.

  2. #2
    misson is offline x10 Spammer
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,573

    Re: Using PHP to create custom zip files for site visitors

    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 by misson; 03-23-2012 at 12:45 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Jon Skeet's and Eric Raymond's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    enox10mx is offline x10Hosting Member
    Join Date
    Jan 2012
    Posts
    29

    Re: Using PHP to create custom zip files for site visitors

    here is an example solution, where I use the function multiple times with IF functions:
    PHP Code:
    $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.

  4. #4
    adam.k is offline x10Hosting Member
    Join Date
    Sep 2008
    Posts
    41

    Re: Using PHP to create custom zip files for site visitors

    Yes, it does have to be 'GET' not 'get'. PHP is a case-sensitive language.

  5. #5
    misson is offline x10 Spammer
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,573

    Re: Using PHP to create custom zip files for site visitors

    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.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Jon Skeet's and Eric Raymond's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

Similar Threads

  1. How to copy the files via FTP to create my web site
    By maximin44 in forum Free Hosting
    Replies: 3
    Last Post: 06-17-2010, 08:35 AM
  2. Site statistics - total visitors by day
    By theproper in forum Free Hosting
    Replies: 2
    Last Post: 10-18-2009, 03:11 AM
  3. site visitors
    By garrensilverwing in forum Scripts, 3rd Party Apps, and Programming
    Replies: 4
    Last Post: 04-13-2009, 07:55 PM
  4. how do i track the visitors to my site?
    By sagar88 in forum Introductions
    Replies: 9
    Last Post: 02-10-2009, 10:39 AM
  5. How can i create an upload page for my visitors?
    By laupkram in forum Scripts, 3rd Party Apps, and Programming
    Replies: 4
    Last Post: 10-29-2007, 09:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
dedicated servers