PHP将网址快捷方式保存到桌面

WBOY
Release: 2016-06-20 13:03:55
Original
1125 people have browsed it

分享一段利用PHP将网址快捷方式保存到桌面的代码,不知道为什么我在360里面不使用urlencode的话,得到的中文文件名会乱码,而在火狐里面必须使用urldecode,使用urlencode也会导致文件名乱码,这个问题先搁置一下,以后有空再研究,但还是可以通过使用php判断浏览器类型来分别使用不同的方法解决了这个乱码的问题,具体函数代码如下。

<p>/*</p>* url 连接地址<br />* filename 存储文件名称<br />*/<br />function downloadShortcuts($url,$filename){<br />	//首先判断浏览器类型<br />	$user_agent=$_SERVER['HTTP_USER_AGENT'];<br />	if(false!==strpos($user_agent,'Firefox')){<br />		$filename=urldecode($filename);<br />	}else{<br />		$filename=urlencode($filename);<br />	}<br />	//生成快捷方式并下载 www.scutephp.com<br />	$Shortcuts='[InternetShortcut]<br />	URL='.$url.'<br />	IDList=<br />	[{000214A0-0000-0000-C000-000000000046}]<br />	Prop3=19,2';<br />	Header('Content-type: application/octet-stream');<br />	header('Content-Disposition: attachment; filename='.$filename.'.url;');<br />	echo $Shortcuts;<br /><p>}
Copy after login

调用示例如下:

downloadShortcuts('http://www.scutephp.com/','SCUtePHP建站');
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!