例如现在要通过a.php文件下载http://www.baidu.com/img/baidu_jgylogo3.gif 这个图片,或者zip文件也行。
然后点击a.php文件时,能弹出另存为窗口,重命名这个文件。。代码得如何写啊??整了好久都不行~~~
然后点击a.php文件时,能弹出另存为窗口,重命名这个文件。。代码得如何写啊??整了好久都不行~~~
解决方案 »
- 做php是windows平台好还是liunx平台好
- 急,PHP二维数据分解与赋值
- PHP有什么作用呢?
- 大家认为哪个cms开源建站程序最好?
- 查询分页时,第一页以后部分无法查询
- 页面传值的问题?
- mysql用PASSWORD修改ROOT用户口令后,如何用PHP连接MYSQL
- 这是?????Fatal error: Maximum execution time of 30 seconds exceeded in E:\webdata\managerinfo.php on line 195
- 这个问题有点难
- php登陆后,如果通过cookie获取登录的用户名?
- 传值执行问题··
- 用socket发邮件 有个问题
$path = 'http://www.baidu.com/img/baidu_jgylogo3.gif';
$file_name="xx.gif"; //这里重命名
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename='.$file_name);
ob_end_clean();
readfile($path);
?>header('Content-Disposition: attachment; filename=xx.gif');
这个头可以激活对话框一个文件介绍php做下载
$path = 'http://www.baidu.com/img/baidu_jgylogxo3.gif';
if(!file_exists($path)){
echo "该文件不存在!!!";
exit();
}
$file_name="xx.gif"; //这里重命名
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename='.$file_name);
ob_end_clean();
readfile($path);
?>
但遇到转向甚至多重转向的情况就相当麻烦了返回状态可以用socket或者curl_getinfo($ch, CURLINFO_HTTP_CODE),或者相关获取连线响应头的方法
最后,其实这个也没办法判断的,如果对方有做针对非合法网址自动处理时,并不一定会返回404
试试用curl。function urlExist($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
curl_close($ch);
if (!$data) {
return "Domain could not be found";
}
else {
preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches);
$code = end($matches[1]);
if ($code == 200) {
return "Page Found";
}
elseif ($code == 404) {
return "Page Not Found";
}
}
}
echo urlExist('http://www.baidu.com/img/baidu_jgylogxo3.gif');
那请问判断head返回状态如何写?