使用 curl 和 PHP 保存文件 [英] Saving file using curl and PHP

查看:49
本文介绍了使用 curl 和 PHP 保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 curl 和 PHP 保存文件?

How can I save a file using curl and PHP?

推荐答案

你想要这样的东西吗?

function get_file($file, $local_path, $newfilename) 
{ 
    $err_msg = ''; 
    echo "<br>Attempting message download for $file<br>"; 
    $out = fopen($local_path.$newfilename,"wb");
    if ($out == FALSE){ 
      print "File not opened<br>"; 
      exit; 
    } 

    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_FILE, $out); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_URL, $file); 

    curl_exec($ch); 
    echo "<br>Error is : ".curl_error ( $ch); 

    curl_close($ch); 
    //fclose($handle); 

}//end function 

功能:它是一个函数,接受三个参数

Functionality: Its a function and accepts three parameters

get_file($file, $local_path, $newfilename)

$file : 是要检索的对象的文件名

$file : is the filename of the object to be retrieved

$local_path : 是存放对象的目录的本地路径

$local_path : is the local path to the directory to store the object

$newfilename : 是本地系统上的新文件名

$newfilename : is the new file name on the local system

这篇关于使用 curl 和 PHP 保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆