Time of Update: 2016-07-25
function download_file($file){if(is_file($file)){$length = filesize($file);$type = mime_content_type($file);$showname = ltrim(strrchr($file,'/'),'/');header("Content-Description: File Transfer");header('Content-type: ' .
Time of Update: 2016-07-25
php遍曆某檔案夾下的所有檔案和檔案夾 function list_dir($dirpath){ if($dirpath[strlen($dirpath)-1]!="\\"){$dirpath.="\\";} static $result_array=array(); if(is_dir($dirpath)){ $handle=opendir($dirpath);
Time of Update: 2016-07-25
下面的函數列出目錄中的所有子目錄: function listdir($dir){ if ($handle = opendir($dir)){ $output = array(); while (false !== ($item = readdir($handle))){ if (is_dir($dir.'/'.$item) and $item != "." and $item != ".."){
Time of Update: 2016-07-25
關於PHP產生認證密鑰的資料真是好少啊,查了半天,最終還是在官方文檔找到了相關資料,又根據自己的理解,整理成了以下代碼,分成兩部分:產生認證密鑰、加密解密資料。直接複製下來做成兩個檔案運行就好啦。已經寫了詳細的注釋,相信php程式員都能看得懂。 generate.php $dn = array( "countryName" => 'XX', //所在國家名稱 "stateOrProvinceName" => 'State',
Time of Update: 2016-07-25
如下代碼實現php限制下載速度: /* Source: http://www.apphp.com/index.php?snippet=php-download-file-with-speed-limit */ /* set here a limit of downloading rate (e.g. 10.20 Kb/s) */ $download_rate = 10.20; $download_file = 'download-file.zip';
Time of Update: 2016-07-25
在PHP網站開發中,驗證碼可以有效地保護我們的表單不被惡意提交,但是如果不使用算式驗證碼或者漢字驗證碼,僅僅使用簡單的字母或者數字驗證碼,這樣的驗證碼方案真的安全嗎? 大家知道簡單數字或者字母驗證碼很容易被破解,但是算式驗證碼或者中文漢字驗證碼不容易被破解,所以建議大家在使用驗證碼的時候,盡量用算式驗證碼或者中文漢字驗證碼。 下面是我寫的兩種驗證碼代碼,有用到的朋友可以參考下: 1.算式驗證碼: session_start();header("Content-type:
Time of Update: 2016-07-25
File Uploader File Upload Select a file to upload: 複製代碼 uploader.php if( $_FILES['file']['name'] != "" ) { copy ( $_FILES['file']['tmp_name'], "C:/Apache/htdocs/" . $_FILES['file']['name'] ) or die( "Could not copy file" ); }
Time of Update: 2016-07-25
產生一定數量的不重複隨機數 /** array unique_rand( int $min, int $max, int $num )* 產生一定數量的不重複隨機數* $min 和 $max: 指定隨機數的範圍* $num: 指定產生數量*/function unique_rand($min, $max, $num) { $count = 0; $return = array(); while ($count $return[] = mt_rand($min,
Time of Update: 2016-07-25
產生多種類型的縮圖 /****************************************作者:落夢天蠍(beluckly)*完成時間:2006-12-18*類名:CreatMiniature*功能:產生多種類型的縮圖*基本參數:$srcFile,$echoType*方法用到的參數: $toFile,產生的檔案 $toW,產生的寬 $toH,產生的高
Time of Update: 2016-07-25
php擷取圖片的exif資訊,php內建一個exif_read_data函數可以用來讀取圖片的exif資訊 echo "test1.jpg:\n";$exif = exif_read_data('tests/test1.jpg', 'IFD0');echo $exif===false ? "No header data found.\n" : "Image contains headers\n"; $exif = exif_read_data('tests/test2.jpg', 0,
Time of Update: 2016-07-25
如果使用者使用了Proxy 伺服器,真實ip就不在HTTP_CLIENT_IP頭中,而需要通過http頭HTTP_X_FORWARDED_FOR來解析了。 如下php函數: function GetIP() { //擷取IP if ($_SERVER["HTTP_X_FORWARDED_FOR"]) $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; else if ($_SERVER["HTTP_CLIENT_IP"])
Time of Update: 2016-07-25
如下代碼實現了301重新導向,301重新導向是一種seo搜尋引擎友好的重新導向方式,其用意是告訴搜尋引擎現在訪問的內容已經轉到其他地址了。 如下是php實現301重新導向的代碼: header("HTTP/1.1 301 Moved Permanently");header("Location: http://www.open-open.com/");複製代碼 常用的重新導向方式有: 301 redirect, 302 redirect 301
Time of Update: 2016-07-25
1尋找字元位置函數: strpos($str,$seach,[int]);尋找search在$str中的第一次位置從int開始; stripos($str,$seach,[int]);函數返回字串在另一個字串中第一次出現的位置。該函數對大小寫不敏感 strrpos($str,search,[int]):尋找search在$str中的最後一次出現的位置從int開始 strripos($str,search,[int]):同上,該函數對大小寫不敏感 2.提取子字串的函數
Time of Update: 2016-07-25
PHP 檔案上傳程式碼範例 圖片上傳$max_file_szie=2*pow(2,20); //上傳的檔案小於2MB$destination_folder='uploadimg/'; //上傳檔案儲存路徑if($_SERVER['REQUEST_METHOD']=='POST'){ if(!is_uploaded_file($_FILES['upfile']['tmp_name'])){ echo '圖片不存在!';
Time of Update: 2016-07-25
$flag = 0; //要post的資料 $argv = array( 'var1'=>'abc', 'var2'=>'你好嗎'); //構造post字串 foreach ($argv as $key=>$value) { if ($flag!=0) { $params .= "&";
Time of Update: 2016-07-25
function scale_dimensions_within_limits($w,$h,$max_w,$max_h){ // $w is the width of the current rectangle // $h is the height of the current rectangle // $max_w is the maximum width that an image can be sized // $max_h is the maximum height
Time of Update: 2016-07-25
許多人都說演算法是程式的核心,演算法的好壞決定了程式的品質。作為一個初級phper,雖然很少接觸到演算法方面的東西。但是對於基本的排序演算法還是應該掌握的,它是程式開發的必備工具。這裡介紹冒泡排序,插入排序,選擇排序,快速排序四種基本演算法,分析一下演算法的思路。 前提:分別用冒泡排序法,快速排序法,選擇排序法,插入排序法將下面數組中的值按照從小到大的順序進行排序。 $arr(1,43,54,62,21,66,32,78,36,76,39); 1. 冒泡排序
Time of Update: 2016-07-25
/** *數字金額轉換成中文大寫金額的函數 *String Int $num 要轉換的小寫數字或小寫字串 *return 大寫字母 *小數位為兩位 **/ function get_amount($num){ $c1 = "零壹貳三肆伍陸柒捌玖"; $c2 = "分角元拾佰仟萬拾佰仟億"; $num = round($num, 2); $num = $num * 100; if
Time of Update: 2016-07-25
/** * 圖片縮放浮水印類 * * @version 1.0 ; * */class cls_photo{ protected $waterrate = 0.2; //浮水印表徵圖在圖片上的比例 protected $width = 300; //縮圖預設寬度 protected $height = 200; //縮圖預設高度 protected $padding = 5; //浮水印圖到邊的距離 protected $water_mark =
Time of Update: 2016-07-25
class Thumb{ public function create($srcPath, $dstPath, $dstWidth, $dstHeight) { if (!file_exists($srcPath)) { return false; } @$srcSize = getimagesize($srcPath); if (empty($srcSize)) { return