Unzip_file causing Media file upload error

Question

When I attempt to use the unzip_file function below in my functions.php:

require_once(ABSPATH . 'wp-admin/includes/file.php');
WP_Filesystem();
$destination = wp_upload_dir();
$destination_path = $destination['path'];
$unzipfile = unzip_file( $destination_path.'/filename.zip', $destination_path);

if ( is_wp_error( $unzipfile ) ) {
    echo 'There was an error unzipping the file.'; 
} else {
    echo 'Successfully unzipped the file!';       
}

I get the following error when trying to upload any files into the Media library in Media > Add New:

An error occurred in the upload. Please try again later.

I am using Twenty Nineteen theme with no plugins activated. I don’t get the error when I remove the function.

Any ideas?

0
Troy Templeman 2 months 0 Answers 13 views 0

Leave an answer