Time of Update: 2016-07-25
//格式化輸出目錄大小 單位:Bytes,KB,MB,GB//也可以用於統計目錄數//site bbs.it-home.orgfunction getDirectorySize($path){ $totalsize = 0; $totalcount = 0; $dircount = 0; if ($handle = opendir ($path)) { while (false !== ($file = readdir($handle))) {
Time of Update: 2016-07-25
/* com_create_guid()是php5版本支援的功能,對於不支援的版本,可以自己進行定義;*/function guid(){ if (function_exists('com_create_guid')){ return com_create_guid(); }else{ mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
Time of Update: 2016-07-25
/*** php檔案下載樣本* by bbs.it-home.org*/ob_start();$ua = $_SERVER["HTTP_USER_AGENT"];$filename ="指令碼學堂_檔案下載.doc";//注意轉碼$encoded_filename = urlencode($filename);//相容各種瀏覽器$encoded_filename = str_replace("+", "%20", $encoded_filename);header('Content-Type:
Time of Update: 2016-07-25
$filename = "document.txt";header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename=' . $filename);print "Hello!";?> 複製代碼用瀏覽器開啟之後,即可下載document.txt。但是,如果$filename是UTF-8編碼的,有些瀏覽器就無法正常處理了。例子: $filename = "中文
Time of Update: 2016-07-25
/*** 替換html內容* by bbs.it-home.org*/function htmlsp($a){ if(strpos($a, ' { echo $a; }else { while(strpos($a, '=0) { if(strpos($a, ' break; $x1 = strpos($a, ' $x2 = strpos($a, '>', 0); if($x2===false) //if 特殊需要,因為內容可能只有結束 $x2 =
Time of Update: 2016-07-25
/*** php 柱狀圖 imagefilledrectugle函數用例* by bbs.it-home.org*/function createImage($data,$twidth,$tspace,$height){ header("Content-Type:image/jpeg"); $dataname = array(); $datavalue = array();//data裡面的值 $i = 0; $j = 0; $k = 0; $num =
Time of Update: 2016-07-25
/*** php GD庫產生折線圖、柱狀圖、餅狀圖* by bbs.it-home.org*/$img_gao=170;$img_kuan=0;$jiange=30;//橫座標點與點之間的間隔,產生的圖片寬度會根據傳入資料的多少而自動變化$zuo=20;//左側留空$you=20;//右側留空$shang=20;//上留空$xia=20;//下留空$zuidashujuzhi=1;$p_x = array();//點橫座標$p_y = array();//點縱座標$y_name=split(",
Time of Update: 2016-07-25
function validation_filter_id_card($id_card){ if(strlen($id_card)==18){ return idcard_checksum18($id_card); }elseif((strlen($id_card)==15)){ $id_card=idcard_15to18($id_card); return idcard_checksum18($id_card); }else{ return false; }}// 計算身份證校正碼,
Time of Update: 2016-07-25
/*** 計算剩餘時間* by bbs.it-home.org*/public function gettime($time_s,$time_n){$time_s = strtotime($time_s);$time_n = strtotime($time_n);$strtime = '';$time = $time_n-$time_s;if($time >= 86400){return $strtime = date('Y-m-d H:i:s',$time_s);}if($time >= 36
Time of Update: 2016-07-25
$fileName = "prefs.csv";header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename=' . $fileName);header('Content-Transfer-Encoding: binary');header('Content-Length: ' . filesize($fileName));readfile($fileName)
Time of Update: 2016-07-25
複製代碼2,執行頁面insertdb.php session_start();header("Content-type:text/html;charset:utf-8");//全域變數$file=$_FILES['filename'];$max_size="2000000"; //最大檔案限制(單位:byte)$fname=$file['name'];$ftype=strtolower(substr(strrchr($fname,'.'),1)); //檔案格式
Time of Update: 2016-07-25
tar -xzvf tiff-3.8.0.tar.gzcd tiff-3.8.0./configuremakemake install 複製代碼我安裝完成後,在命令列處理圖片,報錯:libtiff.so.3: cannot open shared object file: No such file or
Time of Update: 2016-07-25
//寫excel//Include class require_once(‘Classes/PHPExcel.php’); require_once(‘Classes/PHPExcel/Writer/Excel2007.php’); $objPHPExcel = new PHPExcel();/*** phpExcel匯出excel* by bbs.it-home.org*///Set properties 設定檔案屬性
Time of Update: 2016-07-25
$con = mysql_connect("localhost","peter","abc123");if (!$con) { die('Could not connect: ' . mysql_error()); }// some code?>複製代碼關閉串連指令碼一結束,就會關閉串連。如需提前關閉串連,請使用 mysql_close() 函數。 $con = mysql_connect("localhost","peter","abc123");if (!$con) {
Time of Update: 2016-07-25
// 初始化一個 curl 對象$curl = curl_init();// 設定你需要抓取的urlcurl_setopt($curl, curlopt_url, 'http://bbs.it-home.org');// 設定headercurl_setopt($curl, curlopt_header, 1);// 設定curl 參數,要求結果儲存到字串中還是輸出到螢幕上。curl_setopt($curl, curlopt_returntransfer, 1);// 運行curl,請求網頁$
Time of Update: 2016-07-25
介紹下php中檔案上傳大小的設定方法,以及突破php上傳限制的方法,有需要的朋友參考下。在php編程中,突破php上傳大小限制,可以按如下方法操作。開啟php.ini設定檔中的upload_tmp_dir、upload_max_filesize、post_max_size等選項。php.ini中檔案上傳功能配置選項說明開啟php.ini設定檔找到File Uploadsfile_uploads = On預設允許HTTP檔案上傳,此選項不能設定為OFF。upload_tmp_dir =預設為空白,
Time of Update: 2016-07-25
/*** 遠程圖片的下載* by bbs.it-home.org*/header("Content-type:text/html ; charset=utf-8"); if (!empty($_POST['submit'])){ $url = $_POST['url']; $pictureName = $_POST['pictureName']; $img = getPicture($url,$pictureName); echo '';}function
Time of Update: 2016-07-25
為大家舉一個php使用smtp發送郵件的代碼,簡單實用,有需要的朋友,可以參考下。完整代碼如下。 '指令碼學堂', //這裡填寫網站名稱 );$mail = Array ( 'state' => 1, 'server' => 'smtp.abc.com', 'port' => 25, 'auth' => 1, 'username' => 'admin@abc.com', 'password' => '123456', 'charset' => 'gbk', 'mailfrom' =>
Time of Update: 2016-07-25
$fname = $_FILES['MyFile']['name']; $do = copy($_FILES['MyFile']['tmp_name'],$fname); if ($do){ echo"匯入資料成功"; }else{ echo ""; } ?> error_reporting(0);//匯入CSV格式的檔案 $connect=mysql_connect("localhost","a0530093319","123456") or die("could not connect
Time of Update: 2016-07-25
//載入PHPExcel類require './phpexcel/PHPExcel.php';//建立一個excel對象執行個體$objPHPExcel = new PHPExcel();//設定文檔基本屬性$objProps = $objPHPExcel->getProperties();$objProps->setCreator("Lao Mao");$objProps->setLastModifiedBy("Lao Mao");$objProps->setTitle("Office