php - php从数组中获取错误以卷曲url获取文件
问题描述
当来自 URL 的卷曲数据(来自数组的 URL 进入文件)时出现错误。当我使用 Normaly URL 时,它可以正常工作!但是当我从 Array 获取 URL 并为它运行一个循环,并调用函数 curl 来运行每一行 url 时,它不起作用吗?我不知道为什么,但我需要有人帮助我。我打开了错误报告php,但没有错误!
示例文件“link.txt”
https://www.fshare.vn/file/4UNG2NRPW5OQ
https://www.fshare.vn/file/CFTJYXKPMN7Q
https://www.fshare.vn/file/RMHD2XBFY93F
https://www.fshare.vn/file/I4TIUE6E9QOV
https://www.fshare.vn/file/5PV15EB38M7T
https://www.fshare.vn/file/ZDLJNDNWCNYM
https://www.fshare.vn/file/O1VYZUXXJNCI
https://www.fshare.vn/file/SD5C1VZ38IPN
还有我的 PHP 代码
<?php
error_reporting(E_ALL);
$lines = file('link.txt', FILE_IGNORE_NEW_LINES); // Turn Every Line To Array From File , Or use other below Method
//$lines = explode("\n",fopen('link.txt',"r")); // Other Method Get Content To Array
//$lines = explode("\n",file_get_contents('link.txt')); // Other Method Get Content To Array
foreach($lines as $key => $value){
echo $value . "</br>";
echo get_data($value); // It not Work , Why is that ?
echo get_data("https://www.fshare.vn/file/ACKM6ONXFZJE"); // It Work Normally
die();
}
function get_data($url = null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type' => 'application/x-www-form-urlencoded', 'charset' => 'utf-8'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0");
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com.vn/');
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
解决方案
现在,我再次测试,它工作正常!不知道怎么回事!
推荐阅读
- javascript - PanGestureHandler:从下到上重置为底部然后动画
- python - 计算文件中的条目
- java - 错误 java.lang.IllegalArgumentException:org.hibernate.hql.ast.QuerySyntaxException:未映射 Utilisateurt [从 Utilisateurt 中选择 t]
- python - 使用 ubuntu (WSL) 时如何告诉 python 在哪里可以找到 Windows DLL 文件?
- c++ - 用 const 重载 Matrix 类的 [] 运算符
- f# - 参考另一个 F# Jupyter Notebook
- django - 使用 pandas 计算指数移动平均值时抛出异常
- python - 我无法使用 pip 安装模块
- python - 在烧瓶应用程序中使用 ThreadPoolExecutor 内部的 urllib3 请求超时
- windows - 编译后如何分发 Chromium 二进制文件?目录有超过 39GB