By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Zip Files, Mysql, Downloading, & PHP

Ajm113
100+
P: 161
Hello, I created a database and all and have a php page that displays content to the readers when a certain id is entered in the address bar.

What I want to do is to have the user download a zip file that contains copies of that php script, but rename them to a title value of each row, so no replacing is done and display the individual content on each page from that title into the php pages that where made in the zip file.

How can I do this?
Sep 12 '08 #1
Share this Question
Share on Google+
7 Replies


nathj
Expert 100+
P: 938
Hi,

If I understand correctly you may want to take a look at the PHP Zip functions. These should help you create the zip file as you need it.

I've never done this myself so I can't offer any specific tips, however, if you get stuck I'm happy to look over any code and learn as I go.

Cheers
nathj
Sep 12 '08 #2

Ajm113
100+
P: 161
I already looked over them before and their is no File Creation and Content Post in a programmed new file in a php zip file.

Now if I could create fake files of say page.php?id=C5435 TO /page/C5435.php and make the zip file upload thinking it is a actual page then I have something going so it will add a C5435.php file to the zip with the certain content in it so people could download the pages in one zip file.

Then I have something going, but I think this requires some Apache configuration.
Sep 12 '08 #3

nathj
Expert 100+
P: 938
Okay, well as I said before this is not something I've done myself.

If I could ask why you need this I may be able to get some more insight into what you are trying to achieve.

Cheers
nathj
Sep 12 '08 #4

Ajm113
100+
P: 161
Have you ever seen something like 'Download' Wikipedia articles or PHP.net manual pages you can get in one click?

Its on their website, but just like my project I want to allow users to download my web pages in one click for offline purposes (Laptops) of my database in html format so you can take important information if you don't have internet access currently and it won't slow you down working on your project.
Sep 12 '08 #5

nathj
Expert 100+
P: 938
Have you ever seen something like 'Download' Wikipedia articles or PHP.net manual pages you can get in one click?

Its on their website, but just like my project I want to allow users to download my web pages in one click for offline purposes (Laptops) of my database in html format so you can take important information if you don't have internet access currently.

Okay, I think i understand the aim of the game. why is the speciofied format ZIP? Could you use the header functions and php echo statements to create a file that is then saved to the users machine> Here's a code sample of what I mean.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. function __autoload($pcClassName)
  3. {    
  4.         require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/' . $pcClassName . '.php' ;
  5. }
  6. session_start();  
  7. $loDataObject    = new dataObject() ;    
  8. // Dates must be in the format YYYYMMDD    
  9. switch($_GET['type'])
  10. {
  11. case 1: // all future events
  12. $lcEventsSelect = "SELECT a.ID, a.title, a.summary, concat(date_format(a.startDate, '%Y%m%d'), 'T', date_format(a.startTime, '%H%i%S')) as start, concat(date_format(a.endDate, '%Y%m%d'), 'T', date_format(a.endTime, '%H%i%S')) as end, b.name as location FROM tbl_event a LEFT OUTER JOIN tbl_venue b on b.ID = a.venueID WHERE a.startDate>now() AND a.publishDate<=now() ORDER by startDate ASC" ;
  13. break;
  14. case 2: // all my bookings
  15. $lcEventsSelect = "SELECT a.ID, a.title, a.summary, concat(date_format(a.startDate, '%Y%m%d'), 'T', date_format(a.startTime, '%H%i%S')) as start, concat(date_format(a.endDate, '%Y%m%d'), 'T', date_format(a.endTime, '%H%i%S')) as end, b.name as location FROM tbl_event a LEFT OUTER JOIN tbl_venue b on b.ID = a.venueID WHERE a.startDate>now() AND a.publishDate<=now() AND a.ID IN (SELECT c.eventID FROM tbl_userevent c WHERE c.userID=$lnUserID) ORDER by startDate ASC" ;
  16. break;
  17. }
  18. $laEvent = $loDataObject->queryGetData(false,$lcEventsSelect);
  19. // Define the file as an iCalendar file
  20. header("Content-Type: text/Calendar");
  21. // Give the file a name and force download
  22. header("Content-Disposition: inline; filename=clocalendar.ics");
  23. // Header of ics file
  24. echo "BEGIN:VCALENDAR\n";
  25. echo "VERSION:2.0\n";
  26. echo "PRODID:PHP\n";
  27. echo "METHOD:REQUEST\n";
  28. // Loop through results and create an event for each item
  29. foreach($laEvent as $laEventRow)
  30. {
  31.     echo "BEGIN:VEVENT\n";
  32.     // The end date of an event is non-inclusive, so if the event is an all day event or one with no specific start and stop
  33.     // times, the end date would be the next day.  
  34.     echo "DTSTART:".$laEventRow['start']."\n";
  35.     echo "DTEND:".$laEventRow['end']."\n";
  36.     // Only create Description field if there is a description
  37.     if(isset($laEventRow['summary']) && $laEventRow['summary'] != '')
  38.     {
  39.             echo "DESCRIPTION:";
  40.             echo $laEventRow['summary']."\n";
  41.     }
  42.     if(isset($laEventRow['location']) && $laEventRow['location'] != '')
  43.     {
  44.             echo "LOCATION:";
  45.             echo $laEventRow['location']."\n";
  46.     }
  47.     echo "SUMMARY:{$laEventRow['title']}\n";
  48.     echo "UID:{$laEventRow['ID']}\n";
  49.     echo "SEQUENCE:0\n";
  50.     echo "DTSTAMP:".date('Ymd').'T'.date('His')."\n";
  51.     echo "END:VEVENT\n";
  52. }
  53. echo "END:VCALENDAR\n";
  54.  
What this does is create an iCal file based on my database and download it to the users machine. It does this when and only when they ask for it - via a link on the page.

Surely you could use something similar - each page has a link on it that fires up code like that above to generate, in your case, an HTML file. this could be one routine parameterised to handle retrieve any database content.

The obvious flaw with this is linked files - style sheets, images that sort of thing - which is presumably why you want to use a ZIP file - package everything up as a mini version of the site.

Couldn't you simply direct the user to their browsers capability for making the age available off line? Or provide a print style sheet so they can print it and take it away? I know if I want a page available off-line I print it using a PDF printer and then I have a PDF copy of it.

So, there's my latest ramblings on the matter, I'll continue to give it some thought - it's an interesting problem.

I'll post back if I come up with anything else.

Cheers
nathj
Sep 12 '08 #6

nathj
Expert 100+
P: 938
what about using this class Using this along with code to generate a file you could generate file on the fly, add it to the ZIP file, download the ZIP file and the delete the temporary file.

The code would need some loops and a possibly some directory creation depending on the code in the temporary file but it could just work.

I still think most users who want to take a page off line will know how in their browser.

Cheers
nathj
Sep 12 '08 #7

Ajm113
100+
P: 161
Thanks, but I got tons of pages with notes and instructions on fixing errors.

So I need something for the user not wasting more time downloading the million pages and just instead download them in one click where they can get those pages individualy in a zip file, becuase the user won't know what he'll run into when he recives errors on a applications.

Thats the point of the website I am making, pretty much. I'll play with the code later today.
Sep 12 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.