WordPress.org

Ready to get started?Download WordPress

Forums

Unzip_file is not working (5 posts)

  1. 5tapl3r
    Member
    Posted 1 year ago #

    I'm creating a plugin right now that tries to download a zip file and then extract it to my plugin directory. I can download it just fine, but I can't extract it using the unzip_file function.

    Here is my code:

    $path =  plugin_dir_path(__FILE__);
    $remote_file = 'file.zip';
    $local_file = $path . 'file.zip';
    
    $ftpstream = ftp_connect('ftpname');
    $login_result = ftp_login($ftpstream, 'ftp-username', 'ftp-password');
    ftp_get($ftpstream, $local_file, $remote_file, FTP_BINARY);
    ftp_close($ftpstream);

    The part above works perfecly fine, the file gets downloaded, but here is the problem:

    chmod( $local_file, 0777 );
    WP_filesystem();
    unzip_file( $local_file, $path );

    I checked and everything (downloading, giving file permission) works. It just doesn't seem to extract and also never return any error.
    I think the problem comes from calling WP_filesystem incorrecly, but I can't find how to make it work...

    Thank you for your help!

  2. 5tapl3r
    Member
    Posted 1 year ago #

    I forgot to add: I did require_once the file.php page in wp-admin/includes, so that isn't the problem...

  3. ClaytonJames
    Member
    Posted 1 year ago #

    I think the problem comes from calling WP_filesystem incorrecly, but I can't find how to make it work

    This is a tad over my head, but does anything here look at all helpful?

    http://codex.wordpress.org/Filesystem_API

    There's an external reference link at the bottom of that page, as well.

  4. 5tapl3r
    Member
    Posted 1 year ago #

    I read both those pages you linked and both didnt help me much... It seems like they keep talking about form, but I just don't use any form, everything is automated.

  5. bcworkz
    Member
    Posted 1 year ago #

    The filesytem API appears to be very useful, but it's not well documented. For simply extracting zipped files, I would use the PHP ZipArchive class and the extractTo method.
    http://www.php.net/manual/en/ziparchive.extractto.php

    There may still be permission issues to resolve.

Topic Closed

This topic has been closed to new replies.

About this Topic