ip轉(zhuǎn)換:php中將ip轉(zhuǎn)換成整型的函數(shù)ip2long()容易出現(xiàn)問題,在ip比較大的情況下,會(huì)變成負(fù)數(shù),代碼如下:
- <?php
- $ip = "192.168.1.2";
- $ip_n = ip2long($ip);
- echo $ip_n; //得到 -1062731518
- ?>
由于ip轉(zhuǎn)換成的整型值太大超出了整型的范圍,所以變成負(fù)數(shù),需寫成$ip_n = bindec(decbin(ip2long($ip)));這樣便可得到無(wú)符號(hào)的整型數(shù),如下代碼:
- <?php
- $ip = "192.168.1.2";
- $ip_n = bindec(decbin(ip2long($ip)));
- echo $ip_n; //得到 3232235778
- ?>
文件下載代碼如下:
- <?php
- header("content-type: application/force-download");
- header("content-disposition: attachment; filename=ins.jpg");
- readfile("imgs/test_zoom.jpg");
- ?>
第一行代碼是強(qiáng)制下載;
第二行代碼是給下載的內(nèi)容指定一個(gè)名字;
第三行代碼是把下載的內(nèi)容讀進(jìn)文件中;
example #1 forcing a download using readfile()
- <?php
- $file = 'monkey.gif';
- if (file_exists($file)) {
- header('content-description: file transfer');
- header('content-type: application/octet-stream');
- header('content-disposition: attachment; filename='.basename($file));
- header('content-transfer-encoding: binary');
- header('expires: 0');
- header('cache-control: must-revalidate, post-check=0, pre-check=0');
- header('pragma: public');
- header('content-length: ' . filesize($file));
- ob_clean();
- flush();
- readfile($file);
- exit;
- }
- ?>
新聞熱點(diǎn)
疑難解答