简体   繁体   中英

File transfer all images inside a folder to a destination folder via plugin during activation

I have a WordPress plugin that, when first activated, sets up some default site settings and creates and adds a few widgets to the site.

I'd like to add some code to my plugin so that during the activation process, it grabs all images inside a folder named "images" (located in the same directory as the plugin script) and transfers them all to the "uploads" folder in WordPress (located at wp-content/uploads).

Can someone provide an example of the code methods required to do this file transfer?

If PHP is running as the owner of the files and directories involved, you can simply call rename with the old location and the new location of each file.

File ownership may be an issue, so your code should be prepared to deal with failures by checking the return value of the function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM