I successfully created zip file in root folder of WordPress using following code:
$files = array(__DIR__.'/test.jpg', __DIR__.'/screenshot.png');
$zipname="images.zip";
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE) or die(' cant open ');
foreach ($files as $file) {
if( $zip->addFile($file)){
echo "<br>$file Added To Zip Sucessfully";
}else {
echo "<br>Can not add $file file";
}
}
$zip->close();
if(file_exists($zipname)){
echo "<a href="https://wordpress.stackexchange.com/questions/398433/$zipname" download> Download $zipname</a> ";
}else{
echo "$zipname not Exists!";
}
I give a full path of images using __DIR__
and test each step by printing messages. you can provide a download link if it is not automatically downloaded. I hope it helps.
Related Posts:
- Reliable way to add nonce to HTTP Header in WordPress?
- I can’t fetch query parameters ($_GET parameters) with get_query_var
- Dynamic URL to reference custom PHP files
- Prevent multiple counts by same user – WP PostViews plugin
- How to use a frontend URL with a Plugin
- WordPress template_include filter not working properly
- Theme url in all plugin pages
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- How to display a value from a radio button in the options menu in wordpress
- How to access function from outside of a class within this class in WP plugin?
- PHP can I add line numbers to file_get_contents()
- How to call function at the bottom of post using plugin?
- Echo URL of large version of Featured Image
- WP add_action factory
- Swapping wp_dropdown_categories function with wp_category_checklist
- How to show phpinfo() only in a new tab?
- How can I remove a function that has been added to wordpress with add_filter?
- Use custom post type for a store locator
- How do I programmatically set a user as spam in BuddyPress? [closed]
- How to use $_GET function WordPress backend
- WP CRON duplicate wp_insert_post with has < and > tag
- How to send Ajax request from my plugin in admin dashboard?
- Extend PHP regex to cover “srcset” and “style” attributes
- AJAX success response is not working but it’s saving my changes
- Best practice for show data to one specific user?
- How can I hide that I Use WordPress (with W3 Total Cache)
- Headers already sent in Pluggable.php / homepage and wp-login error
- Saving plugin settings – ERROR: options page not found
- class_exists returns different values [closed]
- Adding Meta Tags to a Post using its Tags, Excerpt and content
- Moving code from theme header to functions.php
- WordPress wp_redirect error
- Custom array from a query only write the last row of the query
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- What does -> mean in WordPress?
- Clickable image link sends people to wrong URL
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- Custom meta box values are not getting saved for my custom post type
- WordPress shortcode returns the data before
- Can’t upload CSV file to plugin directory using custom upload form in admin panel
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Can I remove or edit an include() from a function with a filter?
- Call to undefined function error in plugin
- How do I make this Metabox show current DB value?
- Get category id when SEO URL is turned on
- can’t unzip file
- WP_REST_Response – How to return Gzip answer and add Content-encoding header?
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- Using ACF Relationship field to set post type to draft or published status
- Settings API form – submit with AJAX
- How to change basename url for wp-admin?
- Only the first image uploads
- WordPress loading progess – wp-blog-header.php
- Illegal string offset checkbox
- Custom plugin: how do I call a PHP file if settings option is set to true?
- Trying to use a variable to set image width
- wp_update_post gives 500 internal error
- How to identify which php file a plugin is using on page load?
- dashboard widget form not submit mails
- register_setting not save checkbox
- How to import woocommerce custom fields data into another site?
- Using Javascript On Page – Header and Footer Now Missing
- Add a custom link to each image in WordPress gallery
- How to access this jQuery/AJAX data in a PHP file/WordPress plugin
- post_exists stops working in a scheduled event
- register dependency css and js inside a plugin class
- How does one make a URL return dynamic JSON with custom Content Type?
- Change headers for one custom PHP file
- How to give custom roles the capability to edit one Menu instead of every Menu
- Premature end of script headers: wp-mail.php?
- setcookie() issues on running with HTTPS on WordPress
- Allow user to choose header style
- add menu page in loop menu order
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- Use header option on wp-login page with a second logo
- PHP get_category() function redeclared
- Private messaging – Getting and displaying the avatar/url of a message recipient
- I’m writing my first plugin and my echo output is showing up on every page of my wordpress installation
- wp_query (or hook) posts by date (id) in array then set post_type
- Chosen Select jquery Not Working in Plugin
- widget: input the px value from user and use it as inline style in widget function
- PHP calling function within a class
- Custom post type single page return to listing page
- Save data of select list after clicking save
- Create and update Custom Cookie based on multiple GET and POST Values for first time visitors?
- WordPress rewrite question
- Using Nonce for my Form
- Create new folder and upload files to custom folder via wp_handle_upload
- Converting Menu Links to List Elements
- Cannot get custom javascript to execute on page
- SHARING TO FACEBOOK – FROM DYNAMICALLY GENERATED PAGE
- Cannot modify header information – headers already sent
- How to hide Ads From Certain Categories?
- Custom field fetch error on woocommerce pdf invoice
- Login user into magento using wordpress account
- Redirect users by role to custom pages
- getJSON response to PHP
- Custom plugin with shortcode not working
- Customize create table SQL statement in any WordPress plugin
- How can I modify the html output of a custom post type admin page?