WordPress函数:download_url 下载远程文件到本地临时文件

追格官方小助手/ 2022年07月25日/ WordPress/ 浏览 1706

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 );


需要注意的是,把临时文件拷贝到需要的地方后,务必删除临时文件。

发表评论

暂无评论,抢个沙发...

客服 工单