国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 語(yǔ)言 > PHP > 正文

php常用ip轉(zhuǎn)換與文件下載代碼

2024-09-04 11:44:55
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

ip轉(zhuǎn)換:php中將ip轉(zhuǎn)換成整型的函數(shù)ip2long()容易出現(xiàn)問題,在ip比較大的情況下,會(huì)變成負(fù)數(shù),代碼如下:

  1. <?php 
  2. $ip = "192.168.1.2"
  3. $ip_n = ip2long($ip); 
  4. echo $ip_n;      //得到 -1062731518 
  5. ?> 

由于ip轉(zhuǎn)換成的整型值太大超出了整型的范圍,所以變成負(fù)數(shù),需寫成$ip_n = bindec(decbin(ip2long($ip)));這樣便可得到無(wú)符號(hào)的整型數(shù),如下代碼:

  1. <?php 
  2. $ip = "192.168.1.2"
  3. $ip_n = bindec(decbin(ip2long($ip))); 
  4. echo $ip_n;      //得到 3232235778 
  5. ?> 

文件下載代碼如下:

  1. <?php 
  2. header("content-type: application/force-download"); 
  3. header("content-disposition: attachment; filename=ins.jpg");  
  4. readfile("imgs/test_zoom.jpg"); 
  5. ?> 

第一行代碼是強(qiáng)制下載;

第二行代碼是給下載的內(nèi)容指定一個(gè)名字;

第三行代碼是把下載的內(nèi)容讀進(jìn)文件中;

example #1 forcing a download using readfile()

  1. <?php 
  2. $file = 'monkey.gif'
  3.  
  4. if (file_exists($file)) { 
  5.     header('content-description: file transfer'); 
  6.     header('content-type: application/octet-stream'); 
  7.     header('content-disposition: attachment; filename='.basename($file)); 
  8.     header('content-transfer-encoding: binary'); 
  9.     header('expires: 0'); 
  10.     header('cache-control: must-revalidate, post-check=0, pre-check=0'); 
  11.     header('pragma: public'); 
  12.     header('content-length: ' . filesize($file)); 
  13.     ob_clean(); 
  14.     flush(); 
  15.     readfile($file); 
  16.     exit
  17. ?> 

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 原阳县| 武强县| 高安市| 中牟县| 景泰县| 温宿县| 崇仁县| 武宣县| 新野县| 鹤壁市| 高安市| 钟山县| 天镇县| 广汉市| 密山市| 新田县| 台东县| 大城县| 沂源县| 蕉岭县| 探索| 读书| 乌鲁木齐县| 万盛区| 南涧| 泸定县| 佛山市| 郴州市| 灌南县| 墨玉县| 郯城县| 阿拉善盟| 西吉县| 汤阴县| 凭祥市| 华坪县| 建宁县| 荔浦县| 武冈市| 延安市| 富宁县|