Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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