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!
]]>The problem I have is that it constantly returns “true.” I had this issue in another thread and some one suggested to return the function unzip_file() its self instead of just return true. So I did that, and according to the doc this method, unzip_file() returns true if it did what you asked it to or wp_error.
I get true. You’d think that’s a good thing,but the file I have, which over writes a current file is not overwriting that file, that is to say my local copy of said file is not being replaced with the zipped one.
is it because the path to the zip file is a url and not a “path”? would it not throw an error? my logs and WP_DEBUG are clean when this method is run.
Ideas?
Update So I don’t think I am using the function properly. I tried giving it a path to no where and it still returned true…. I have read the doc a thousand times
Note: not sure why paste bin is formatting my code so poorly….
]]>[Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]
Essentially this function is called to do an update of the theme. I thought I understood the codex but I guess not. Could some one expalin why this is returning true for uzipping files to specified directory?
AISIS = the root of the Aisis Theme folder. It should unzip a zip file containing new files for the theme, over write old ones with the new ones and then return true. it returns true but it doesn’t over write the files with the new file.
the old file was 1.0 before running this function, then after it was still 1.0 even though the new file that was suppose to over write the old file was 1.1…
Could some explain what I am doing wrong?
]]>WordPress(Apache) has write privilege for my uploads dir so it should be able to use direct file system access; however, I’ve found that in my plugin the wp_filesystem is trying to use the FTP ‘driver’. If I add define('FS_METHOD', 'direct');
before calling WP_Filesystem(); and force the direct fs access driver I’m able to use WP_Filesystem as expected.
I’ve tried WP_Filesystem(array(), 'path/to/my/uploads/dir');
which doesn’t work even though I can write to that path from php in my plugin. Clearly I’m not understanding how get_filesystem_method works when called by WP_Filesystem.
I don’t want to use FS_METHOD define to force wp_filesystem to the correct driver (for my particular server) as a long term solution. (TL;DR)So what should I be passing for $args and $context to WP_Filesystem to allow the auto detection by get_filesystem_method to work?
]]>WordPress(Apache) has write privilege for my uploads dir so it should be able to use direct file system access; however, I’ve found that in my plugin the wp_filesystem is trying to use the FTP ‘driver’. If I add define('FS_METHOD', 'direct');
before calling WP_Filesystem(); and force the direct fs access driver I’m able to use WP_Filesystem as expected.
I’ve tried WP_Filesystem(array(), 'path/to/my/uploads/dir');
which doesn’t work even though I can write to that path from php in my plugin. Clearly I’m not understanding how get_filesystem_method works when called by WP_Filesystem.
I don’t want to use FS_METHOD define to force wp_filesystem to the correct driver (for my particular server) as a long term solution. (TL;DR)So what should I be passing for $args and $context to WP_Filesystem to allow the auto detection by get_filesystem_method to work?
]]>