Time of Update: 2016-07-25
由於項目需要,需要本機伺服器接收資料後,再將資料轉寄到另外一台伺服器上,故要用到類比post請求發送資料,當然資料中也包含檔案流。 curl是php比較常用的方式之一,一般代碼如下: $params1 = "test"; $params2 = "@".$absolute_path;//如果是檔案 則參數為"@"+絕對路徑 $post_data = array( 'params1' => $params1,
Time of Update: 2016-07-25
如果你需要下載特定的檔案而不用另開新視窗,下面的程式碼片段可以協助你。 function force_download($file) { $dir = "../log/exports/"; if ((isset($file))&&(file_exists($dir.$file))) { header("Content-type: application/force-download");
Time of Update: 2016-07-25
$pdf_file = './pdf/demo.pdf';$save_to = './jpg/demo.jpg'; //make sure that apache has permissions to write in this folder! (common problem)//execute ImageMagick command 'convert' and convert PDF to JPG with applied settingsexec('convert "'.$
Time of Update: 2016-07-25
通過不斷的定位基準數的位置來實現快速排序 /** * Created by PhpStorm. * User: saint * Date: 15/8/5 * Time: 上午11:49 */class Demo{ public $a = array(3, 6, 9, 2, 4, 7, 1, 5, 8, 0); public function qsort($left, $right) { if($left > $right) {
Time of Update: 2016-07-25
使用下面的 PHP 片段可以即時壓縮 zip 檔案 function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && !$overwrite) { return false; }
Time of Update: 2016-07-25
getValidate(100,30); function getValidate($w,$h){ $img = imagecreate($w,$h); $gray = imagecolorallocate($img,255,255,255); $black = imagecolorallocate($img,rand(0,200),rand(0,200),rand(0,200));
Time of Update: 2016-07-25
Mandrill 是一款強大的 SMTP 提供器。開發人員傾向於使用一個第三方 SMTP provider 來擷取更好的收件交付。 下面的函數中,你需要把 “Mandrill.php” 放在同一個檔案夾,作為 PHP 檔案,這樣就可以使用TA來發送郵件。 function send_email($to_email,$subject,$message1){require_once 'Mandrill.php';$apikey = 'XXXXXXXXXX'; //specify your
Time of Update: 2016-07-25
function detect_city($ip) { $default = 'UNKNOWN'; $curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)'; $url =
Time of Update: 2016-07-25
一次壓縮多個CSS檔案 header('Content-type: text/css');ob_start("compress");function compress($buffer) {/* remove comments */$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);/* remove tabs, spaces, newlines, etc. */$buffer =
Time of Update: 2016-07-25
$dir = './'; // set to current folderif ($handle = opendir($dir)) { while(false!== ($file = readdir($handle))) { if ( is_file($dir.$file) ){ if (preg_match("'\.(avi)$'", $file) ){ $sub_file = str_ireplace(".avi", ".srt", $dir.$file); $idx_file = str_
Time of Update: 2016-07-25
一、getdata.php namespace Webadmin\Model;use ExtendSpace\Excel; …… 略 …… // 取出資料 $dataBillArr = $this->get_list_bysql($sql); // 替換資料中的 0 、1 為 是、否 // PHPExcel 有內建的方法處理,但是得到的是 TRUE/FALSE,這裡自己處理吧
Time of Update: 2016-07-25
$f = file('words.txt');$words = array();foreach ($f as $w) { $words[] = preg_quote(trim($w), '/');}$text = file_get_contents('text.txt'); $start = microtime(true);$reg = '/' . implode('|', $words) . '/S'; preg_match_all($reg, $text, $m); $result =
Time of Update: 2016-07-25
define( 'NL', "\n" );define( 'TB', ' ' );// connecting to MySQL.$conn = @mysql_connect( 'localhost', 'username', 'password' ) or die( mysql_errno().': '.mysql_error().NL );// attempt to get a list of MySQL databases// already set up in my
Time of Update: 2016-07-25
支援文字浮水印、圖片浮水印支援浮水印的位置隨機或固定(九宮格)浮水印透明度設定(圖片浮水印和文字浮水印都支援)文字 浮水印的字型、顏色、大小設定圖片浮水印的背景透明 /** * 加浮水印類,支援文字圖片浮水印的透明度設定、浮水印圖片背景透明。 * 日期:2011-09-27 * 作者:www.itwhy.org * 使用: * $obj = new WaterMask($imgFileName); //執行個體化對象 * $obj->$waterType =
Time of Update: 2016-07-25
/** * 下載遠程圖片到本地 * * @param string $url 遠程檔案地址 * @param string $filename 儲存後的檔案名稱(為空白時則為隨機產生的檔案名稱,否則為原檔案名稱) * @param array $fileType 允許的檔案類型 * @param string $dirName 檔案儲存的路徑(路徑其餘部分根據時間系統自動產生) * @param int $type 遠程擷取檔案的方式 * @return json 返迴文件名、檔案的儲存路徑 *
Time of Update: 2016-07-25
PHP目錄的遍曆 //php目錄的遍曆function showDetail($dirname){$ds = opendir($dirname);while($file = readdir($ds)){$path = $dirname."/".$file;if($file != "." && $file != ".."){ //這裡是個坑if(is_dir($path)){showDetail($path);
Time of Update: 2016-07-25
if ( !isset($_REQUEST["url"]) ) exit; $u = $_REQUEST["url"]; if (substr($u, -0, 7) != "http://") exit; echo file_get_contents( $u );/* function getPage($url, $referer, $timeout, $header=true){ if(!isset($timeout)) $timeout=30;
Time of Update: 2016-07-25
//擷取年月日對應的最近的周天的到期日 可能會 跨年 跨月 跨周function GetClearWeek() { $year_month_day_over = array(); $year = date('Y'); //四位 的年份 $month = date('n'); //1 到 12 $day_of_month = date('j');//1-31 月份中的第幾天 $day_of_week = date('N'); //1-7 周中的第幾天
Time of Update: 2016-07-25
1 給圖片進行浮水印添加 2產生一個新的縮率圖 class Image{ //浮水印配置項 private $waterOn; private $waterImg; private $waterPos; private $waterPct; private $waterText; private $waterFont; private $waterTextSize;
Time of Update: 2016-07-25
$img=imagecreatetruecolor(100, 40);$red=imagecolorallocate($img, 255, 0, 0);$green=imagecolorallocate($img, 0, 255, 0);$blue=imagecolorallocate($img, 0, 0, 255);$white=imagecolorallocate($img, 255, 255, 255);$black=imagecolorallocate($img, 0, 0, 0);/