如何使用PHP实现远程文件下载操作.txt?
- 内容介绍
- 文章标签
- 相关推荐
本文共计128个文字,预计阅读时间需要1分钟。
pythondef download_remote_file(url, filename, timeout=60): import requests try: response=requests.get(url, timeout=timeout) response.raise_for_status() with open(filename, 'wb') as file: file.write(response.content) return True except requests.RequestException as e: return str(e)
远程文件下载.txt/** * 下载远程文件 * @param string $url 网址 * @param string $filename 保存文件名 * @param integer $timeout 过期时间 * @return boolean|string */ function http_down($url, $filename, $timeout = 60) { $path = dirname($filename); if (!is_dir($path) && !mkdir($path, 0755, true)) { return false; } $fp = fopen($filename, 'w'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_exec($ch); curl_close($ch); fclose($fp); return $filename; }
本文共计128个文字,预计阅读时间需要1分钟。
pythondef download_remote_file(url, filename, timeout=60): import requests try: response=requests.get(url, timeout=timeout) response.raise_for_status() with open(filename, 'wb') as file: file.write(response.content) return True except requests.RequestException as e: return str(e)
远程文件下载.txt/** * 下载远程文件 * @param string $url 网址 * @param string $filename 保存文件名 * @param integer $timeout 过期时间 * @return boolean|string */ function http_down($url, $filename, $timeout = 60) { $path = dirname($filename); if (!is_dir($path) && !mkdir($path, 0755, true)) { return false; } $fp = fopen($filename, 'w'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_exec($ch); curl_close($ch); fclose($fp); return $filename; }

