Results 1 to 3 of 3

Thread: Compress folder using zip command with PHP

  1. #1
    Join Date
    May 2012
    Beans
    364

    Compress folder using zip command with PHP

    Hello everybody,

    While using zip command line with PHP to add a folder into an archive file:

    General command:

    Code:
    zip archive.zip file.mp3

    PHP code:
    PHP Code:
     <?php
    $path2mp3 
    '../Downloads/Medias/MP3/001.mp3';
    $site 'site.com';
    $compressFolder $site.'.zip';
    $cmd "zip -r $compressFolder $path2mp3";
                            
    $compressMP3 exec($cmd ." 2>&1" );
    echo 
    $compressMP3;
                            
    if(
    $compressMP3)
    {
    echo 
    'Done';
    }
    else
    {
    echo 
    'Not Done';
    }

    ?>
    Output:

    Code:
    updating: ../Downloads/Medias/MP3/001.mp3 (deflated 6%)
    I cannot find the file, and I don't know whether it is created or not.

    In command line:

    Code:
    $ zip archive.zip 001.mp3 
      adding: 001.mp3 (deflated 6%)
    $ ls
    archive.zip
    Thanks in advance

  2. #2
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    13,000
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: Compress folder using zip command with PHP

    Are you running this script via Apache or at the command-line?

    If the former, you may have file permission issues since any files created will be owned by user www-data and must be placed in a directory to which www-data has write permissions.

    If you are running this at the command line, why are you using PHP? Just write a shell script.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  3. #3
    Join Date
    May 2012
    Beans
    364

    Re: Compress folder using zip command with PHP

    it is a PHP script, not a command line:

    PHP Code:
    $cmd 'cd ../MP3 && /usr/bin/zip --password pass --encrypt -r '.$path2root.$compressedFile.'  *.mp3'
    using password will protect the zip file, how about the option --encrypt, what is the use for?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •