顯示具有 PHP 標籤的文章。 顯示所有文章
顯示具有 PHP 標籤的文章。 顯示所有文章

2013年5月9日 星期四

Install Apache + PHP + MySQL use Homebrew

在原生的Mac也就是你一開始拿到Mac的時候

就已經安裝Apache, PHP,但是版本不是最新的

接著下面就是使用Homebrew來安裝


Apache
brew tap djl/homebrew-apache2 
brew install djl/apache2/apache24

接著httpd.conf
vi /usr/local/Cellar/apache24/2.4.4/conf/httpd.conf
增加下面
LoadModule php5_module    /usr/local/opt/php54/libexec/apache2/libphp5.so
AddType application/x-httpd-php .php

PHP
brew tap homebrew/dupes 
brew tap josegonzalez/homebrew-php
brew options php54
brew install php54 --homebrew-apxs

MySQL
brew install mysql


參考資料
http://sobstel.org/blog/pow-nginx-apache-ruby-php-all-through-port-80/
https://github.com/josegonzalez/homebrew-php
http://justinhileman.info/article/reinstalling-php-on-mac-os-x/

2013年4月16日 星期二

Install MAMP Development stack on Mountain Lion using MacPorts

這是一篇從網路上轉載的別人寫好了MAMP(Mac, Apache, MySQL, PHP)使用MacPorts來完成

因為Mac本身就有預載Apache, PHP,不過版本可能不是最新的

前半步驟都在先更新軟體

接下來在做設定

大家可以參考下面的連結:
https://gist.github.com/TeamOneJ/4210358
http://2tbsp.com/content/install_apache_2_and_php_5_macports

2012年6月4日 星期一

使用Android將檔案傳到Server use PHP

首先先說明Android

在這邊是使用HttpClient來實現上傳,程式如下
public void UploadFiles(String PathFile) {
    new Thread() {  
        @Override  
        public void run() {  
            super.run();  
            
            List< NameValuePair> params = new ArrayList< NameValuePair>();
            params.add(new BasicNameValuePair("file",PathFile));
            
            HttpClient client = new DefaultHttpClient();
            HttpPost post = new HttpPost("Server Address/update.php");
            
            try{
                //setup multipart entity
                MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

                for(int i=0;i< params.size();i++){
                    //identify param type by Key
                    if(params.get(i).getName().equals("file")){
                        File f = new File(params.get(i).getValue());
                        FileBody fileBody = new FileBody(f);
                        entity.addPart("image"+i,fileBody);
                    }else{
                        entity.addPart(params.get(i).getName(),new StringBody(params.get(i).getValue()));
                    }
                }
                post.setEntity(entity);

                //create response handler
                ResponseHandler< String> handler = new BasicResponseHandler();
                //execute and get response
                UploadFilesResponse = new String(client.execute(post,handler).getBytes(),HTTP.UTF_8);
                if(D) Log.e(TAG, "--- response ---"+ UploadFilesResponse);
            }catch(Exception e){
                e.printStackTrace();
            }
        }  
    }.start();  
}

粉紅字是你要上傳檔案的路徑
紅色字是你的Server路徑


接著在Server寫一隻PHP檔案

update.php
<?php 
    if(move_uploaded_file($_FILES['image0']['tmp_name'], "./ImageFiles/".$_FILES['image0']['name'])){
        echo "uploaded";
    }else{
        echo "unsuccessfully";
    }
?>

因為在Android在上傳資料寫法,是使用多檔案上傳的方式,也就是For迴圈那邊,

所以在PHP也應該是這樣寫,但我PHP並沒直接跑迴圈,就直接抓第一筆  $_FILES['image0']


如果在PHP有必要接收兩個檔案以上,直接在裡面加入迴圈,就可以了



最後記得在Server的路徑建立資料夾,不然傳不上去








2011年8月24日 星期三

在 FreeBSD上的Apache,PHP的一些小設定

目前這個設定是針對我們Lab,大概就openssl不一樣

php.ini
-------------------------------------------------
error_reporting = E_ALL & ~E_NOTICE

extension=php_openssl.dll   

date.timezone = "Asia/Taipei"

short_open_tag = On


httpd.conf
-------------------------------------------------
AllowOverride All 




解釋

php.ini
-------------------------------------------------
error_reporting = E_ALL & ~E_NOTICE    #是要讓PHP對變數不要太嚴警

extension=php_openssl.dll   #因為Gmail的關係所以會要拿掉

date.timezone = "Asia/Taipei"  #設定時區

short_open_tag = On   #開啟短標籤  <?   ?> 


httpd.conf
------------------------------------------------
AllowOverride All  #讓.htaccess可以執行

2011年8月9日 星期二

[PHP] 將Mysql 的時間轉換到PHP 並轉換格式

這裡就不講怎麼從 Mysql 抓值

&lt;?php 
    echo date("l, M d, Y",  strtotime($row['date']));
    echo date("h:i A",  strtotime($row['date'])); 
?&gt;


mysql date : 2011-08-06 03:53:32
php echo : Saturday, Aug 06, 2011 03:53 AM

2011年8月8日 星期一

[PHP] 上傳圖片

 最近用php寫一個上傳圖片的程式

HTML
<form name="form1" action="" method="post" enctype="multipart/form-data">
    <label><input name="file" type="file"></label>
</form>

PHP
$file_name= $_FILES['file']['name']; //檔案名字
$file_temp_name = $_FILES['file']['tmp_name']; //伺服器上暫存檔名
$DestDIR = '............./'.$file_name;
move_uploaded_file($file_temp_name, $DestDIR); //將上傳的檔案儲存到指定的目錄

這樣就完成了!!

其中可以用 is_uploaded_file(file) 這個函數去判斷是否有上傳檔案
函數連結:http://php.net/manual/en/function.is-uploaded-file.php

參考網站:http://ckone1209.com/blog/?p=306
                http://blog.yam.com/eviles/article/10921956