Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 13th, 2006, 3:50 PM   #1
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
PHP to ZIP a directory.

I need to zip all the files in a directory (not including the folder). i tried to use an example on www.php.net/sip to help me but i get a parse error. heres the whole code i have. The SQL statments insert it into a PHP nuke evo database. it already puts the files in the downloads section but i want it to include the ZIP file (as if to download all files).

<?php
$server = 'cali';
$etmain_cid = '3';
$etpub_cid = '';
$jaymod_cid = '4';
$etpro_cid = '';



$date = date('Y-m-d H-i-s');
$etmain = './etmain';
$etpub = './etpub';
$jaymod = './jaymod';

mysql_connect('localhost','***','***');


////////////////////////////////////
////////////Etmain/////////////////
//////////////////////////////////


$zip = new ZipArchive();
$filename = "./allfiles-$date";

while($file1 = readdir($directory1)) {



		if($file1 != "." && $file1 != ".." && $file1 != "index.html"){
		$stat1 = stat("$etmain/$file1");
		$filesize1 = $stat[7];
		echo '<tr><td>' . $file1 . '</td><td>' . $filesize1 . '</td></tr>';



if ($zip->open($filename1, ZIPARCHIVE::CREATE)!==TRUE) {
** exit("cannot open <$filename>\n");
}

$zip->addFile($etmain . "/$file1");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();



}
}




mysql_query("DELETE FROM c1hess_phpnuke.nuke_downloads_downloads WHERE cid='$etmain_cid'");
if($directory = opendir($etmain)){
echo '<table border="1">Etmain additions:';
while($file = readdir($directory)) {

		if($file != "." && $file != ".." && $file != "index.html"){
		$stat = stat("$etmain/$file");
		$filesize = $stat[7];
		echo '<tr><td>' . $file . '</td><td>' . $filesize . '</td></tr>';


mysql_query("INSERT INTO c1hess_phpnuke.nuke_downloads_downloads (`cid`,`title`,`url`,`description`,`date`,`submitter`,`filesize`,`sub_ip`,`active`) VALUES ('$etmain_cid','$file','http://www.1hess.com/modsandmaps/$server/etmain/$file','Game File for [HESS] $server download to etmain.','$date','Piercy\'s directory bot','$filesize','$ip','1')");

}
}
echo '</table>';





closedir($directory);
}
?>

the parse error i get is:
Parse error: parse error, expecting `'('' in /Users/mike/sites/untitled folder/index.php on line 37

line 37 is:

if ($zip->open($filename1, ZIPARCHIVE::CREATE)!==TRUE) {


usually parse errors are easy to solve but i dont really know what im doing with the zip code.

Thanks in advance,
Piercy
__________________
this forum rules you guys are great!
thanks to all who help
piercy
piercy is offline   Reply With Quote
Old Nov 14th, 2006, 5:58 PM   #2
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 237
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
Hi,

I didn't examine the code very in-depth, but I do see that you are probably going to have some problems where you attempt to include the contents of variables into parameters and or strings.

an example would be

php Syntax (Toggle Plain Text)
  1. stat("$etmain/$file1");

how about trying this instead

php Syntax (Toggle Plain Text)
  1. stat($etmain. "/" .$file1);


there are other occurrences in this code where you do similar things with your variables. try fixing these up and then post back what you get and we'll work on the next step.
__________________
I have never let my schooling interfere with my education. -Mark Twain-

Xbox live gamertag: melbolt
melbolt is offline   Reply With Quote
Old Nov 21st, 2006, 1:16 PM   #3
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
currently rewriting the whole code to fix these errors and a few other ones. will carry on with zipping once i fixed it.

Thanks for help,
__________________
this forum rules you guys are great!
thanks to all who help
piercy
piercy is offline   Reply With Quote
Old Nov 23rd, 2006, 5:08 PM   #4
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
Would someone be able to supply a general zipping code for zipping a whole directory? This should help me then i can add it to what ive got.
__________________
this forum rules you guys are great!
thanks to all who help
piercy
piercy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining the contents of a directory grimpirate PHP 2 Nov 5th, 2006 3:59 PM
Allow user to select a directory MegaArcon HTML / XHTML / CSS 11 Jun 5th, 2006 8:38 AM
how to recursively copy or move part of a directory limited by size? linuxpimp20 Bash / Shell Scripting 2 Jul 6th, 2005 11:51 AM
Directory Nellie C++ 11 Jun 8th, 2005 4:31 PM
Bash script to access all files in a directory shinni Bash / Shell Scripting 4 Feb 18th, 2005 3:26 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:42 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC