Zip Files, Mysql, Downloading, & PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ajm113
    New Member
    • Jun 2007
    • 161

    Zip Files, Mysql, Downloading, & PHP

    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?
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    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

    Comment

    • Ajm113
      New Member
      • Jun 2007
      • 161

      #3
      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=C54 35 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.

      Comment

      • nathj
        Recognized Expert Contributor
        • May 2007
        • 937

        #4
        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

        Comment

        • Ajm113
          New Member
          • Jun 2007
          • 161

          #5
          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.

          Comment

          • nathj
            Recognized Expert Contributor
            • May 2007
            • 937

            #6
            Originally posted by Ajm113
            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.
            Code:
            <?php
            function __autoload($pcClassName)
            {	
            		require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/' . $pcClassName . '.php' ;
            }
            session_start();  
            $loDataObject	= new dataObject() ;	
            // Dates must be in the format YYYYMMDD	
            switch($_GET['type'])
            {
            case 1: // all future events
            $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" ;
            break;
            case 2: // all my bookings
            $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" ;
            break;
            }
            $laEvent = $loDataObject->queryGetData(false,$lcEventsSelect);
            // Define the file as an iCalendar file
            header("Content-Type: text/Calendar");
            // Give the file a name and force download
            header("Content-Disposition: inline; filename=clocalendar.ics");
            // Header of ics file
            echo "BEGIN:VCALENDAR\n";
            echo "VERSION:2.0\n";
            echo "PRODID:PHP\n";
            echo "METHOD:REQUEST\n";
            // Loop through results and create an event for each item
            foreach($laEvent as $laEventRow)
            {
                echo "BEGIN:VEVENT\n";
                // 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
                // times, the end date would be the next day.  
                echo "DTSTART:".$laEventRow['start']."\n";
                echo "DTEND:".$laEventRow['end']."\n";
                // Only create Description field if there is a description
                if(isset($laEventRow['summary']) && $laEventRow['summary'] != '')
                {
                        echo "DESCRIPTION:";
                        echo $laEventRow['summary']."\n";
                }
            	if(isset($laEventRow['location']) && $laEventRow['location'] != '')
                {
                        echo "LOCATION:";
                        echo $laEventRow['location']."\n";
                }
                echo "SUMMARY:{$laEventRow['title']}\n";
                echo "UID:{$laEventRow['ID']}\n";
                echo "SEQUENCE:0\n";
                echo "DTSTAMP:".date('Ymd').'T'.date('His')."\n";
                echo "END:VEVENT\n";
            }
            echo "END:VCALENDAR\n";
            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

            Comment

            • nathj
              Recognized Expert Contributor
              • May 2007
              • 937

              #7
              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

              Comment

              • Ajm113
                New Member
                • Jun 2007
                • 161

                #8
                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.

                Comment

                Working...