这是我的代码:
<?php
$name="19875379";
$url = "https://p-ams2.pcloud.com/cfZef5XTZVizxYkZNTGjZZsikL67Z2ZZKYRZZrYP6e7ZgVZQZTVZ4XZN7Zw7ZfVZBkZgXZLVZokZJ7ZxZ1XZ6MJPDKvi9cQXwzvKARfMHfHsN5WX/SH-LMP-SS-JUN15.zip".$name;
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$header = curl_exec($ch);
$redir = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
//print_r($header);
$x = preg_match("/<script>location.href=(.|\n)*?<\/script>/", $header, $matches);
$script = $matches[0];
$redirect = str_replace("<script>location.href='", "", $script);
$redirect = "http://www.pcloud.com" . str_replace("';</script>", "", $redirect);
echo $redirect;
?>
&安培;输出是:
Notice: Undefined offset: 0 in C:\xampp\htdocs\58.php on line 18
http://www.pcloud.com
在解析它时,我在这个PHP代码中做错了吗。
答案 0 :(得分:0)
https://p-ams2.pcloud.com/cfZef5XTZVizxYkZNTGjZZsikL67Z2ZZKYRZZrYP6e7ZgVZQZTVZ4XZN7Zw7ZfVZBkZgXZLVZokZJ7ZxZ1XZ6MJPDKvi9cQXwzvKARfMHfHsN5WX/SH-LMP-SS-JUN15.zip
链接已损坏。也许重定向是标题位置,而不是脚本标记?
或尝试一下;
$ tevsi() { wget --server-response $1 2>&1 | grep "^Location"; }
$ tevsi https://p-ams2.pcloud.com/cfZef5XTZVizxYkZNTGjZZsikL67Z2ZZKYRZZrYP6e7ZgVZQZTVZ4XZN7Zw7ZfVZBkZgXZLVZokZJ7ZxZ1XZ6MJPDKvi9cQXwzvKARfMHfHsN5WX/SH-LMP-SS-JUN15.zip