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?
- PHP: $_SESSION destroyed after page reload for my custom session
- send popup after wp_redirect()
- WordPress – Get Posts with Category data
- no_rest_route error on custom routes
- Add a custom WooCommerce settings tab with sections
- Flatten Responses returned via WP REST API via WP_Error for obfuscation
- can’t unzip file
- How to use wp_send_json() and output the value with ajax?
- How do you remove header sitewide from mobile only?
- How does add_option() function enable action hooks to fire right after actiavtion?
- How to correctly escape an echo
- PHP using external anonymous function inside class
- 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?
- Problem with inserting multiple images in gallery of each WooCommerce product programmatically
- Is it possible to access admin-ajax.php using PHP?
- Payment field disappears on custom Paypal plugin
- Call to “admin_notices” hook from a static method
- How to Create custom block for displaying information in content section which act like shortcode
- Using ACF Relationship field to set post type to draft or published status
- Adding image upload in tag section – WordPress plugin development
- How to detect and handle the time difference between server and user in WordPress?
- How do I use an iFrame for my header in WordPress twenty seventeen?
- Create plugin with custom page and template caused an error `Call to undefined function get_header()`
- How to Remove Theme Style CSS inside Custom Plugin?
- How to setup the Email piping in WordPress plugin?
- Create ACF Checkbox to get all ACF Values from Parent Page
- Settings API form – submit with AJAX
- How to extend SelectControl with data from my theme
- How to change basename url for wp-admin?
- Post form – AJAX won’t upload featured image – Plugin development
- Creating plugin with front-end pages
- Prevent WordPress from sending set-cookie http header
- How to Send Pingbacks for all Posts in WordPress?
- I am having errors with checkout on wordpress
- How to remove get_header From all single pages in wordpress with functions.php without plugin?
- Only the first image uploads
- Getting an error when my plugin is updated, but the files update correctly
- WordPress loading progess – wp-blog-header.php
- Display values of current POST request on page
- Creating a POP Alert
- Add Pre-Defined Value to Click Counter in WordPress
- Illegal string offset checkbox
- File is executed twice if plugin is activating
- ssl redirect function is not working
- product_type_options get saved value [closed]
- Custom plugin: how do I call a PHP file if settings option is set to true?
- Plugin won’t output characters with diacritics properly
- Trying to use a variable to set image width
- How can i avoid duplicate same post in wp?
- Drop down question
- Display a custom name when the user has no name settle in his account
- wp_update_post gives 500 internal error
- WP Hook Before a post is created
- WordPress Plugin Development – get_option error
- how to add new PHP page in WordPress plugin
- How do I disable cache for a certain page?
- How can I get my WordPress plugin to receive data and relay it in an ajax/php request to a remote server that requires authentication?
- code that I can run, or a plug in to show what sql tables something pulls information from
- Automatic email message after manual user approval
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- Changing ALT-tag for logo in wordpress
- Submit remote form to wordpress REST API and save data to custom post type
- How to check if plugin update process completed in wordpress?
- Foreach Loop Of Post Types With Nested If Else If Not Completing Process
- ACF relationship on user profile page used for allowed access
- How to identify which php file a plugin is using on page load?
- dashboard widget form not submit mails
- In a foreach loop, how can I add a meta value if it doesn’t exist?
- Looping through and combining calls to Woocommerce REST API
- Should I use wp_cache in my plugin to make it faster?
- custom mailchimp form using HTTP API
- How to override theme’s public static function inside of a trait?
- pass datetime using wp_localize_script to frontend from settings page
- register_setting not save checkbox
- add custom metabox to media library custom widget
- using filter and hook inside class
- 400 bad request admin-ajax file upload
- Store user form submitted information in post type
- Constant expression contains invalid operations plugin class properties visibility
- How to import woocommerce custom fields data into another site?
- get Woocommerce product format json for WP_Query
- Using Javascript On Page – Header and Footer Now Missing
- Display attached images of a page or post that are insetred using gallery
- overwrite wordpress gallery with custom gallery shortcode
- Add a custom link to each image in WordPress gallery
- Gutenberg blocks shortcodes compatibility
- Enqueue sripts and styles only if function is called
- Problem with my Login Plugin
- Add widget area from visual editor
- Save custom field on WP_List_Table
- How to access this jQuery/AJAX data in a PHP file/WordPress plugin
- How to return html as a string from php for WordPress
- Load script and styles using an array of resources
- Register/enqueue scripts only on certain admin pages
- post_exists stops working in a scheduled event
- Looping through custom data in a custom table to display all items in a post
- register dependency css and js inside a plugin class
- Sum All the Post Meta of Published posts of Current Logged in user