WordPress 提供了一个专门下载文件的函数:download_url。参数 $url, $timeout, $signature_verification 分别是:远程文件地址,超时时间,是否验证。
使用举例:
$file_url = 'https://example.com/myfile.ext';
$tmp_file = download_url( $file_url );
// Sets file final destination.
$filepath = ABSPATH . 'wp-content/uploads/myfile.ext';
// Copies the file to the final destination and deletes temporary file.
copy( $tmp_file, $filepath );
@unlink( $tmp_file );
需要注意的是,把临时文件拷贝到需要的地方后,务必删除临时文件。
-
WordPress函数:is_main_site 是否是主站点WordPress函数:is_main_site 是否是主站点
-
WordPress函数:is_child_theme 是否正在使用子主题WordPress函数:is_child_theme 是否正在使用子主题
-
WordPress函数:current_theme_supports 检查主题对给定功能的支持WordPress函数:current_theme_supports 检查主题对给定功能的支持
-
WordPress函数:is_customize_preview 是否在自定义设置程序中预览网站WordPress函数:is_customize_preview 是否在自定义设置程序中预览网站
-
WordPress函数:wp_get_attachment_image_srcset 响应式图片再 WordPress 中如何设置响应式图片
-
WordPress函数:set_transient 设置临时值WordPress函数:set_transient 设置临时值
暂无评论,抢个沙发...