Time of Update: 2016-07-25
//檢測檔案類型//by http://bbs.it-home.orgfunction checkFileType($filename){ //檔案頭 $_typecode = array( '3780',//PDF '8075',//.docx,.xlsx,.pptx,.potx,.vsdx,.odt '208207',//.doc,.xls,.ppt,.vsd,.pot,.wps,.dps,.et );
Time of Update: 2016-07-25
var_dump(is_file('a_file.txt')) . "\n";var_dump(is_file('/usr/bin/')) . "\n";?> 複製代碼輸出:bool(true)bool(false)例2: function isfile($file){return preg_match('/^[^.^:^?^-][^:^?]*.(?i)' . getexts() . '$/',$file);//first character cannot be . : ? -
Time of Update: 2016-07-25
//取檔案的副檔名//by http://bbs.it-home.org$file = "/home/jbxue/file_20130322.txt";for($i=1; $i $func = 'get_file_ext_' . $i;var_dump($func($file));}function get_file_ext_1($file) {return strtolower(trim(substr(strrchr($file, '.'), 1)));}function
Time of Update: 2016-07-25
$url = 'http://xxxx.com'; $hander_array = get_headers ( $url ); if ($header_array [0] == 'HTTP/1.1 200 OK') { echo '檔案存在'; } else { echo '檔案不存在'; } 複製代碼說明:get_headers
Time of Update: 2016-07-25
var_dump(is_dir('a_file.txt')) . "\n";var_dump(is_dir('bogus_dir/abc')) . "\n";var_dump(is_dir('..')); //one dir up?> 複製代碼輸出:bool(false)bool(false)bool(true)例2: $file = "images";if(is_dir($file)){echo ("$file is a directory");}else{echo ("$file is
Time of Update: 2016-07-25
//二維數組 按索引值 排序function array_sort($array,$keys,$type='desc'){if(!isset($array) || !is_array($array) || empty($array)){return '';}if(!isset($keys) || trim($keys)==''){return '';}if(!isset($type) || $type=='' || !in_array(strtolower($type),array('asc',
Time of Update: 2016-07-25
//樹型目錄結構模板程式//菜單目錄庫欄位說明://menu_id 功能表項目 id//menu 菜單名稱//menu_grade 菜單等級 1 為主菜單 2 為二級菜單 ........//menu_superior 上一級菜單 id 號function my_menu($menu_content,$i,$menu_grade_temp,$menu_superior_temp){global $PHP_SELF;$temp1=$menu_grade_temp+1;$menu_superior_
Time of Update: 2016-07-25
為大家介紹一下php中的三個檔案或目錄判斷函數:file_exists、is_dir、is_file的區別,有興趣的朋友,可以瞭解下。有人這樣說,PHP的 file_exists = is_dir + is_file,呵呵,為什麼這樣說類?file_exists函數既可以判斷檔案是否存在,又可以判斷目錄是否存在。不過它的執行效率非常低,就像asp中request不指定是form,還是get,cookies,所以,聰明的你,一定可以順暢理解下面的總結:1、如果要判斷目錄是否存在,請用獨立函數
Time of Update: 2016-07-25
瀏覽器的類型現在是越來越多,編程時難免要考慮相容性的問題,有時需要根據判斷瀏覽器類型來載入不同的樣式類型。本文的代碼可以判斷IE6、IE7、IE8、firefox、chrome等瀏覽器。以下代碼使用$_SERVER["HTTP_USER_AGENT"],進行判斷,可以判斷IE6、IE7、IE8、firefox、chrome等主流瀏覽器。瀏覽器類型檢測的文章,還可以看下這二篇:php 擷取訪問者瀏覽器的代碼php判斷瀏覽器類型,瀏覽器語言等資訊的代碼
Time of Update: 2016-07-25
php過濾$_GET 和$_POST參數,以防止注入的代碼,有需要的朋友,可以參考下。完整代碼如下。$value){if(!is_array($value)){$value = get_magic_quotes_gpc()?$value:addslashes($value);$array[$key]=filterHtml($value);}Else{Add_S($array[$key]);}}return $array;}function glstr($var) {if
Time of Update: 2016-07-25
/** * 產生頁碼列表 * * @param int $element_total_count 元素總數 * @param int $current_page 當前頁 * @param int $per_page_elem_count 每頁元素數 * @param int $show_page_num 列表顯示的頁碼數 * @param string $up_down_class 上下翻頁樣式 * @param string $num_class 當前頁頁碼數字樣式 * @param
Time of Update: 2016-07-25
$mime_types = array( 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'bmp' => 'image/bmp', 'png' => 'image/png', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'pict' => 'image/x-pict', 'pic' =>
Time of Update: 2016-07-25
Class PAGE {//類開始 /********************************************************* $total 記錄總數* $pageNum 每頁顯示的條數* $url = '' 連結* $page->StartPage(顯示分類統計,字元分類/數字分頁,跳轉);* $page->StartPage(true/false, true/false, true/false);* site
Time of Update: 2016-07-25
//擷取網卡MAC地址@exec("ipconfig/all",$array); for($Tmpa;$Tmpaif(eregi("Physical",$array[$Tmpa])){ $mac=explode(":",$array[$Tmpa]); echo $mac[1]; } }//擷取url主域//by http://bbs.it-home.orgfunction GetDomain($url){$pattern =
Time of Update: 2016-07-25
二級目錄下的頁面,子目錄下也存在htaccess檔案,配置有自己的規則,根目錄的301跳轉規則對子目錄無效,需要在子目錄下重作301重新導向。(301重新導向)子目錄與根目錄的不同之處:訪問地址後面有沒有加斜杠所請求的地址會有不同,規則如下:RewriteBase /newsRewriteCond %{HTTP_HOST} ^jbxue.com [NC]RewriteRule com(.*)$ http://bbs.it-home.org$1
Time of Update: 2016-07-25
php 上傳檔案並產生縮圖的代碼,分為單檔案與多檔案上傳,並可以產生縮圖,確實不錯,建議大家參考學習下。完整代碼如下。* ******************************************************/function UpLoadFileAll($input='UpPic', $path='upload', $ftype='jpg,gif,png', $fsize=2){$fileInfo = $_FILES[$input];
Time of Update: 2016-07-25
本文中實現了一個簡單的php類,以權型結構列出指定目錄下的所有檔案,有興趣的朋友,可以看看。以樹型結構列出指定目錄裡的所有檔案,這樣的話,目錄下的所有檔案便結構清晰的呈現在你的面前,有什麼檔案你一看便知,很方便的哦。樣本,getFileList( $t->getPath() ), "\n" );function arrayValuesToString( $ar, $nl="", $dolast=true ) {//調用函數$str = "";reset( $ar );$size =
Time of Update: 2016-07-25
php資料庫操作類,實現表的增刪改查,擷取行數,查詢多條資料記錄,左串連查詢,建立資料表結構等。功能豐富,方便移值,有需要的朋友,可以參考下。php資料庫類完整代碼與樣本如下。1、代碼links = mysql_connect(DB_HOST, DB_USER, DB_PWD);if(DEBUG){mysql_select_db(DB_NAME) or die('ERROR:'.mysql_error());}else{mysql_select_db(DB_NAME);}$char_sql =
Time of Update: 2016-07-25
php 格式化數字,位元不足時前面加0補足,本文提供了兩種實現方法,分別用sprintf與number_format來實現。有需要的朋友,快來看看吧。php格式化數位例子。一、字串sprintf()函數文法sprintf(format,arg1,arg2,arg++) 參數 描述 format 必需。轉換格式。
Time of Update: 2016-07-25
一段php實現json增加積分的代碼,對於掌握如何在php中構造json資料很有協助,有需要的朋友,可以參考下。 代碼如下,僅供學習參考。 function zeng_integral(){ $jifen=& m('integral'); /*判斷網吧*/ $store=isset($store_id)?intval($store_id):0;