相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
- PHP中opcode緩存簡(jiǎn)單用法分析
- thinkPHP控制器變量在模板中的顯示方法示例
- PHP move_uploaded_file() 函數(shù)(將上傳的文件移動(dòng)到新位置)
- dirname(__FILE__)的含義和應(yīng)用說(shuō)明
- thinkPHP5框架實(shí)現(xiàn)分頁(yè)查詢功能的方法示例
- PHP中單雙號(hào)與變量
- PHP獲得當(dāng)日零點(diǎn)時(shí)間戳的方法分析
- Laravel ORM對(duì)Model::find方法進(jìn)行緩存示例詳解
- PHP讀寫文件高并發(fā)處理操作實(shí)例詳解
- 【CLI】利用Curl下載文件實(shí)時(shí)進(jìn)度條顯示的實(shí)現(xiàn)
php生成網(wǎng)頁(yè)桌面快捷方式
本文將介紹使用PHP生成網(wǎng)頁(yè)桌面快捷方式的代碼,并添加圖標(biāo)及解決不同瀏覽器保存出現(xiàn)的亂碼問(wèn)題。
我們?cè)L問(wèn)網(wǎng)站時(shí),如果網(wǎng)站的內(nèi)容很有吸引,一般我們都會(huì)使用瀏覽器的收藏夾功能,收藏此網(wǎng)站。
在瀏覽器收藏的網(wǎng)頁(yè),需要打開(kāi)瀏覽器,再?gòu)氖詹貖A選定訪問(wèn)。
如果可以在桌面直接進(jìn)入到網(wǎng)站,這樣可以為用戶訪問(wèn)提供便利。
我們可以使用php創(chuàng)建網(wǎng)頁(yè)的快捷入口文件,保存到用戶桌面,方便用戶快速訪問(wèn)。
生成代碼如下:
<?php $filename = '破曉領(lǐng)域.url'; $url = 'http://fdipzone.com/'; $icon = 'http://fdipzone.com/favicon.ico'; createShortCut($filename, $url, $icon); /** * 創(chuàng)建保存為桌面代碼 * @param String $filename 保存的文件名 * @param String $url 訪問(wèn)的連接 * @param String $icon 圖標(biāo)路徑 */ function createShortCut($filename, $url, $icon=''){ // 創(chuàng)建基本代碼 $shortCut = "[InternetShortcut]\r\nIDList=[{000214A0-0000-0000-C000-000000000046}]\r\nProp3=19,2\r\n"; $shortCut .= "URL=".$url."\r\n"; if($icon){ $shortCut .= "IconFile=".$icon.""; } header("content-type:application/octet-stream"); // 獲取用戶瀏覽器 $user_agent = $_SERVER['HTTP_USER_AGENT']; $encode_filename = rawurlencode($filename); // 不同瀏覽器使用不同編碼輸出 if(preg_match("/MSIE/", $user_agent)){ header('content-disposition:attachment; filename="'.$encode_filename.'"'); }else if(preg_match("/Firefox/", $user_agent)){ header("content-disposition:attachment; filename*=\"utf8''".$filename.'"'); }else{ header('content-disposition:attachment; filename="'.$filename.'"'); } echo $shortCut; } ?>