下载服务 php,文件下载: 云---php服务---pc
php下載文件的代碼為:
function download_file($url = '', $fileName = '')
{
$ch = curl_init();
$fp = fopen($fileName, 'wb');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
那怎么從php服務(wù)下載到本地pc呢(上傳可以用html的form表單)? ? 可以在php上寫個(gè)test.php服務(wù), 然后在瀏覽器訪問便是下載, test.php內(nèi)容為:
$result = file_get_contents("......mp4"); // 填寫資源所在路徑
header('Content-Type:application/octet-stream');
header('Content-Disposition:attachment; filename="download.mp4"');
echo $result;
?>? ? ? ? 試了一下, 靠譜。
總結(jié)
以上是生活随笔為你收集整理的下载服务 php,文件下载: 云---php服务---pc的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php mvc单入口搭建,PHP实现MV
- 下一篇: 梯度下降 最小二乘法 matlab,最小