简体   繁体   English

在激活过程中通过插件将文件夹内的所有图像文件传输到目标文件夹

[英]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. 我有一个WordPress插件,在首次激活时,它会设置一些默认网站设置,并创建一些小部件并将其添加到该网站。

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). 我想在插件中添加一些代码,以便在激活过程中,它将抓取名为“ images”(与插件脚本位于同一目录)的文件夹中的所有图像,并将它们全部传输至“ uploads”文件夹在WordPress中(位于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. 如果PHP以相关文件和目录的所有者身份运行,则可以简单地使用每个文件的旧位置和新位置调用rename

File ownership may be an issue, so your code should be prepared to deal with failures by checking the return value of the function. 文件所有权可能是一个问题,因此您的代码应准备通过检查函数的返回值来处理失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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