Jump to content

neekworld

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Female

neekworld's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. ok i have searched this site as well as 4 others looking for help on this. I am trying to download an entire folder based on a username that is input into a text box. i want to zip the file first as it will be holding images. then save the zipped file to my local machine. the current script i have is put together from 2 other scripts that i found online, sorry i dont remember now where exactly i got them from as i have changed them numerous times and i have about 6 variations now. the script i have does exactly what i want with 2 exceptions. 1. it saves the zipped file to the server not to my local machine 2. it only added the files that i hard code into the zip.php script. not the folder that i put into the text box. this is the script im using. i added the headers to force the dialog box to pop up so i can save it where i want to, but if anyone knows a better way i would be most grateful. <?php $files_to_zip = array( 'upload_test/user/2009-07-01-214005Logo.jpg', 'upload_test/user/2009-07-01-215314orange_bg.gif', 'upload_test/user/2009-07-01-215326emptycart.gif', 'upload_test/user/2009-07-01-223317dash.gif', 'upload_test/user/2009-07-02-020536arrow.gif', 'upload_test/user/2009-07-02-020717check_green.gif' ); //if true, good; if false, zip creation failed $result = create_zip($files_to_zip,'test.zip'); /* creates a compressed zip file */ function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && !$overwrite) { return false; } //vars $valid_files = array(); //if files were passed in... if(is_array($files)) { //cycle through each file foreach($files as $file) { //make sure the file exists if(file_exists($file)) { $valid_files[] = $file; } } } //if we have good files... if(count($valid_files)) { //create the archive $zip = new ZipArchive(); if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } //add the files foreach($valid_files as $file) { $zip->addFile($file,$file); } //debug //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status; //close the zip -- done! $zip->close(); //check to make sure the file exists return file_exists($destination); } else { return false; } } $buffer = file_get_contents($file); /* Force download dialog... */ header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); /* Don't allow caching... */ header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); /* Set data type, size and filename */ header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . strlen($buffer)); header("Content-Disposition: attachment; filename=$filename.zip"); /* Send our file... */ echo $buffer; ?>
  2. yes you will need to do that as well. either directly in the page or via an include file. i like to do the include file because if i change the password or database i only need to change one file versus changing all the pages that need access to the database
  3. first do you have any code that you are using? you said you just purchased webspace. so your hosting service should give you some kind of admin access to set up a database. i have one with 1and1.com and depending on the package you purchased you should have access to where you are saving your files on the server. the main admin screen allows you to select database and once in there its kinda like using phpMyAdmin if you have used it before. all you do is say create database, then create the tables you need in the database, then create fields in your tables for what you need to save. good way to test this is WAMP. it sets up an Apache server on your local machine so you can test your php, mysql and webpages before you upload to the main site you will be using. here is the web page to download it. http://www.wampserver.com/en/ its fairly simple to set up and once you have running. you may need to "install" some of the php classes. by "install" i mean all you have to do is go into the wamp server, click php, then click extension and find the class you need. ie you may need to install certain things such as zip extension. i use the wamp server in conjunction with dreamweaver CS3. if you are using dreamweaver you have to set up a connection to the wamp. on the manage sites link all you have to do is select testing server, set the server mode to php/mysql, access to local/network, testing server folder where you are saving the files usually in C:\wamp\www\(your site here), and set the url prefix to the same as in the same as the server folder not the same "/" just add your site after the / it puts in
  4. going through the code i understand that this part is only to force the dialog box to open $buffer = file_get_contents($filename); /* Force download dialog... */ header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); /* Don't allow caching... */ header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); /* Set data type, size and filename */ header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . strlen($buffer)); header("Content-Disposition: attachment; filename=$filename.zip"); /* Send our file... */ echo $buffer; so this part in theory should put the files into the zip folder right? $files_to_zip = array( 'upload_test/2009-07-01-214005Logo.jpg', 'upload_test/2009-07-01-215314orange_bg.gif', 'upload_test/2009-07-01-215326emptycart.gif', 'upload_test/2009-07-01-223317dash.gif', 'upload_test/2009-07-02-020536arrow.gif', 'upload_test/2009-07-02-020717check_green.gif' ); //if true, good; if false, zip creation failed $result = create_zip($files_to_zip,'my-archive.zip'); /* creates a compressed zip file */ function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && !$overwrite) { return false; } //vars $valid_files = array(); //if files were passed in... if(is_array($files)) { //cycle through each file foreach($files as $file) { //make sure the file exists if(file_exists($file)) { $valid_files[] = $file; } } } //if we have good files... if(count($valid_files)) { //create the archive $zip = new ZipArchive(); if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } //add the files foreach($valid_files as $file) { $zip->addFile($file,$file); } //debug //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status; //close the zip -- done! $zip->close(); //check to make sure the file exists return file_exists($destination); } else { return false; } } now i know the images are hard coded in there which is not what i want to do. but this gives me the same error as the first one. does anyone know what is wrong with the code. and possibly if they know how to put the files into the array dynamically?
  5. ok actually if i change to this header("Content-Disposition: attachment; filename=$filename.zip"); it will put the .zip extension. but it still gives me the error about the file being corrupt when i try to open it. i know im missing part of the code i wasnt sure how to put in the add files to the zip folder once it is created. how do you add the files to it?
  6. ok i have a question. i have spent days searching for a script that will allow me to download the entire contents of a specific folder and zip it so i can save it to my local machine. i have a script that opens the dialog box and even lets me save the file. when it saves however it does not automatically add the .zip extension to the file name. if i add it before i save it, when i try to open it it tells me the file is corrupt, if i try to extract the files it says that the contents are empty. if anyone knows how to fix this i would be most grateful my code is as follows this is the form from my main page. i am trying to allow the user to input a specific file to download and send that variable to the zip.php script. that part actually works it allows me to input a name and it selects the folder with that name on it. <form id="form2" name="form2" method="post" action="zip3.php"> <label>Enter Username to get images for that user<br /> <input type="text" name="userName" id="userName" /> </label> <input name="Submit2" type="submit" /> </form> <?php $userName = $_POST['userName']; $_SESSION['userName'] = $userName; ?> this is the zip3.php script <?php $filename = "upload_test/".$_POST['userName']; $buffer = file_get_contents($filename); /* Force download dialog... */ header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); /* Don't allow caching... */ header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); /* Set data type, size and filename */ header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . strlen($buffer)); header("Content-Disposition: attachment; filename=$filename"); /* Send our file... */ echo $buffer; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.