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服务下载到本地pc呢(上传可以用html的form表单)? 可以在php上写个test.php服务, 然后在浏览器访问test.php便是下载mp4, test.php内容为:
- <?php
-
- $result = file_get_contents("......mp4"); // 填写资源所在路径
- header('Content-Type:application/octet-stream');
- header('Content-Disposition:attachment; filename="download.mp4"');
- echo $result;
-
- ?>
试了一下, 靠谱。