SitePoint Sponsor |
|
User Tag List
Results 1 to 12 of 12
Thread: Zipping and Deleting folders
-
Jun 3, 2003, 17:42 #1
Zipping and Deleting folders
G'day, I am looking for advice on how to efficiently Zip up a directory on a server, download it, and remove it.
I have a system where users upload photos to a site and all their images get stored in a directory. I want the Admin users to be able to download this directory and then be able to delete the directory off the server. Please advise...
-
Jun 4, 2003, 04:25 #2
- Join Date
- Sep 2001
- Location
- Barrie, Ontario
- Posts
- 324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The simple way would be to exec() a tar command to tar and gzip the directory, then move that tarball anywhere you need it. If you need an actual zip file (pkzip compression), you can do the same thing, assuming the server has zip installed.
-
Jun 4, 2003, 05:31 #3
- Join Date
- Oct 2002
- Location
- Iceland
- Posts
- 1,238
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
there does also exist a zip thing in php, take a look at http://is.php.net/manual/en/ref.zip.php.
It is not supported by all servers though and I personally have never used it...- website
-
Jun 4, 2003, 05:37 #4
- Join Date
- Mar 2001
- Location
- Philadelphia, US
- Posts
- 2,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by website
CXII. Zip File Functions (Read Only Access)TuitionFree — a free library for the self-taught
Anode Says... — Blogging For Your Pleasure
-
Jun 4, 2003, 05:39 #5
- Join Date
- Oct 2002
- Location
- Iceland
- Posts
- 1,238
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
oh, curse it
- website
-
Jun 4, 2003, 06:09 #6
- Join Date
- Aug 2001
- Location
- Amsterdam
- Posts
- 788
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
what about
CXIII. Zlib Compression Functions
http://is.php.net/manual/en/ref.zlib.phpthe neigbours (free) WIFI makes it just a little more fun
-
Jun 4, 2003, 06:11 #7
- Join Date
- Mar 2001
- Location
- Philadelphia, US
- Posts
- 2,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by peanuts
TuitionFree — a free library for the self-taught
Anode Says... — Blogging For Your Pleasure
-
Jun 4, 2003, 09:24 #8
Hey guys, I am having a problem using the exec() command at the moment. I use it to create a .tar file, but then try it again to move ("mv") the .tar file, and no luck. My syntax should be correct because I use the exact same in my Terminal and it works. And permissions should be ok I figure. Any ideas?
-
Jun 4, 2003, 09:49 #9
- Join Date
- Sep 2001
- Location
- Singapore
- Posts
- 5,269
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I've got a script (that uses a zip creation class that's in phpmyadmin) to zip files in the ZIP file format. Let me know if you're interested.
-
Jun 4, 2003, 09:55 #10
i am redemption... please enlighten me. restore my faith in PHP (hehe, just kiddin it's the sheeeet!)
-
Jun 4, 2003, 09:59 #11
- Join Date
- Sep 2001
- Location
- Singapore
- Posts
- 5,269
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OK first grab the zip.lib.php file that comes with phpmyadmin - it's the script that does the actual zipping.
Here's a test script (zips 'test2.php' and 'apache_pb.gif' into a file called archivetest.zip) I used to see how it works - you need to do the work of placing the correct files in the zip archive yourself. A loop would do the trick. Sorry for not being clearer, but I'm in a hurry at the moment.
PHP Code:<?php
include("./zip.lib.php");
$file_name = 'test2.php';
$file_contents = file_get_contents($file_name);
$zipfile = new zipfile();
$zipfile->addfile($file_contents, $file_name);
$file_name = 'apache_pb.gif';
$file_contents = file_get_contents($file_name);
$zipfile->addfile($file_contents, $file_name);
$file = $zipfile->file();
$size = sizeof($file);
header("Cache-control: private");
if( stristr($_SERVER['HTTP_USER_AGENT'], 'Gecko') )
header("Content-type: application/x-zip-compressed\n");
else
header("Content-Type: application/octet-stream\n");
header("Content-transfer-encoding: binary\n");
//header("Content-Length: $size" );
$archive_name = 'archivetest';
if( stristr($_SERVER['HTTP_USER_AGENT'], 'Gecko') ) {
header("Content-Disposition: attachment; filename=".$archive_name.".zip");
}
else {
header("Content-Disposition: filename=".$archive_name.".zip","zip");
}
if( !readfile($file) )
echo 'There has been an error archiving the file.';
?>
-
Jun 4, 2003, 10:05 #12
thank you redemption, i be trying this out...
Bookmarks