gpt4 book ai didi

php - curl_setopt() CURLOPT_FOLLOWLOCATION 问题与 TCPDF

转载 作者:搜寻专家 更新时间:2023-10-31 21:41:40 25 4
gpt4 key购买 nike

我已将一个站点移至另一个虚拟主机。当我在本地主机上测试时一切正常,但是当我在线尝试时,我收到以下信息:

curl_setopt() [<a href='function.curl-setopt'>function.curl-setopt</a>]: 
CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or
an open_basedir is set

当我尝试使用 TCPDF 生成 PDF 文件时(第 7542 行生成错误)

7534             if ($imsize === FALSE) {
7535 if (function_exists('curl_init')) {
7536 // try to get remote file data using cURL
7537 $cs = curl_init(); // curl session
7538 curl_setopt($cs, CURLOPT_URL, $file);
7539 curl_setopt($cs, CURLOPT_BINARYTRANSFER, true);
7540 curl_setopt($cs, CURLOPT_FAILONERROR, true);
7541 curl_setopt($cs, CURLOPT_RETURNTRANSFER, true);
7542 curl_setopt($cs, CURLOPT_FOLLOWLOCATION, true);

我该怎么做才能避免这种情况?

最佳答案

如果托管公司/部门不愿意关闭安全模式,解决方法可能是在 php.net http://php.net/manual/ro/function.curl-setopt.php#71313 上找到的有用片段

function curl_redir_exec($ch)
{
static $curl_loops = 0;
static $curl_max_loops = 20;
if ($curl_loops++ >= $curl_max_loops) {
$curl_loops = 0;
return FALSE;
}
curl_setopt_array($ch, array(CURLOPT_HEADER => true, CURLOPT_RETURNTRANSFER => true));
$data = curl_exec($ch);
list($header, $data) = explode("\n\n", $data, 2);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_code == 301 || $http_code == 302) {
$matches = array();
preg_match('/Location:(.*?)\n/', $header, $matches);
$url = @parse_url(trim(array_pop($matches)));
if (!$url) { //couldn't process the url to redirect to
$curl_loops = 0;
return $data;
}
$last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
foreach(array('scheme', 'host', 'path') as $component) {
if (!$url[$component]) {
$url[$component] = $last_url[$component];
}
}
$new_url = $url['scheme'] . '://' . $url['host'] . $url['path']
. ($url['query'] ? '?' . $url['query'] : '');
curl_setopt($ch, CURLOPT_URL, $new_url);
return curl_redir_exec($ch);
} else {
$curl_loops = 0;
return $data;
}
}

关于php - curl_setopt() CURLOPT_FOLLOWLOCATION 问题与 TCPDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10138289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com