使用cURL将外部文件保存到我的服务器

use*_*575 5 php mysql curl

我有一个网站来显示开源电影和视频.

我已经在mysql中保存了网址,并将视频和图像链接到内容服务器.

但是用户抱怨网站速度慢,因为图像是从外部获取的,而且大多数时候Internet Explorer甚至都没有显示图像.

我刚刚了解了cURL,并希望将图像和视频保存到我自己的服务器上,并为原始网站提供镜像.

我在许多地方得到了"curl -O('');"语法来执行任务,但不知道如何在我的php脚本中使用它.

简而言之:我已经将我的表单保存在mysql中.我希望它还将保存文件保存到我的web服务器上的目录中,并将文件路径保存到mysql中的另一列.

欢迎任何形式的帮助.Thanx提前

Ped*_*ito 10

$local_file = "/tmp/filename.flv";//This is the file where we save the information
$remote_file = "http://www.test.com/filename.flv"; //Here is the file we are downloading


$ch = curl_init();
$fp = fopen ($local_file, 'w+');
$ch = curl_init($remote_file);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_exec($ch);
curl_close($ch);
fclose($fp);
Run Code Online (Sandbox Code Playgroud)

我差不多7年后决定更新这个答案. 对于已启用远程主机的用户,您只需使用:
copy()

copy("http://www.test.com/filename.flv", "/some/local/path/filename.flv");
Run Code Online (Sandbox Code Playgroud)

  • 无论如何,我明白了. (2认同)