Jump to content

PHP Zip Question


Jason Curran

Recommended Posts

I'm trying to zip up the folder "website" as seen in the code below.

 

But when I open the Zip file,  the files I am trying to Zip are 5 directories deep in the zip file. Does anyone know a way to have the zip file contain only the actual directory and not all of the directories in the path ?

 

 

<?php

if (system('zip -r /home/path/to/my/website/newzipfile.zip 
                   /home/path/to/my/website')) {
                           
    echo '<p>It worked!</p>';
} else {
    echo '<p>It did NOT work!</p>';
} 

?>

Link to comment
https://forums.phpfreaks.com/topic/161408-php-zip-question/
Share on other sites

I don't use zip but im pretty sure your syntax is off

 

zip [-aABcdDeEfFghjklLmoqrRSTuvVwXyz!@$] [-b path] [-n suffixes] [-t mmddyyyy] [-tt mmddyyyy] [ zipfile [ file1 file2 ...]] [-xi list]

 

for your case shouldn't it be

 

zip -r /home/path/to/my/website/* /home/path/to/my/website/newzipfile.zip

 

that should include /website and everything under it, or remove the -r for just the content of /website

Link to comment
https://forums.phpfreaks.com/topic/161408-php-zip-question/#findComment-851826
Share on other sites

Thanks for the help so far .. the solutions have NOT worked .. and have actually led to some unexpected results .. instead of using example code, I will post the actual code that I am using .. I have two scripts.

 

Script #1 works.

Script #2 does NOT work.

 

I am trying to zip all folders inside the "makefolders" directory. Inside of the "makefolders" directory, I have 2 directories, "test1" and "test2".

 

In Script #1, I am getting the results I am expecting. All of the directories inside of the "makefolders" directory are indluded in the Zip file, but I am also getting all of the directories in the path: "/home/folders/public_html/makefolders"

 

Here is a link to Script #1 live on server where you can download the Zip file that is created: http://www.foldersfromlist.com/working.php

 

Here is the code for Script#1

 

<?php

$dl_url = 'http://www.foldersfromlist.com/testme.zip';

if (system('zip -r /home/folders/public_html/testme.zip /home/folders/public_html/makefolders/'))
{
echo '<p>It worked!</p>';
echo '<a href="' . $dl_url . '">Download</a>';
} else {
echo '<p>It did NOT work!</p>';
}

?> 

 

If I remove the "-r" from Script #1, the directories under "makefolders" are not included in the Zip file, and the directories in the path are still included in the Zip file.

 

Script #2 does not work, with or without the "-r"

 

For Script #2, I tried the code syntax posted by ldoughtery

 

zip -r /home/path/to/my/website/* /home/path/to/my/website/newzipfile.zip 

 

Script #2 actually creates a zip file called "test1.zip" inside of the "makefolders" directory and inside "test1.zip" is the directory "test2"

 

 

Here is a link to Script #2 live on server where you can download the Zip file that is created: http://www.foldersfromlist.com/notworking.php

 

<?php

$dl_url = 'http://www.foldersfromlist.com/testme.zip';

if (system('zip -r /home/folders/public_html/makefolders/* /home/folders/public_html/testme.zip'))
{
echo '<p>It worked!</p>';
echo '<a href="' . $dl_url . '">Download</a>';
} else {
echo '<p>It did NOT work!</p>';
}

?> 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/161408-php-zip-question/#findComment-851904
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.