- Oct 18 Sat 2014 10:18
-
解決 PHP/mySQL 資料庫讀取中文顯示亂碼或問號
- Aug 24 Sun 2014 13:44
-
PHP模板引擎原理

開發一個web項目,通常分為兩部分,一部分是GUI,即界面、美工,使用HTML,CSS,JS編寫,另一部分則是業務邏輯,即程序、功能,使用PHP編寫。而模板引擎則是聯繫這兩部分的「橋樑」,可理解成一個PHP類,裡面定義了許多方法,實現了將PHP的原始輸出加載上界面樣式後再輸出。
- Feb 19 Wed 2014 08:32
-
php fopen download file 下載檔案
$content = "";
$fp = fopen("http://file-to-download.com/a-file.zip", "rb");
if (!$fp)
die("Error opening file.");
while (!feof($fp))
$content .= fread($fp, 2048);
fclose($fp);
$fp=fopen("local-file-name.zip", "w");
fwrite($fp, $content);
fclose($fp);
?>
- Feb 17 Mon 2014 20:41
-
在 php 使用 at 命令 增加排程
你可以在php裡查一下 apache 使用的是哪個 shell,
<?
$output = shell_exec('echo $SHELL');
echo $output;
?>
centos 預設 apache 的 shell 是 /bin/nologin
在linux 裡改
usermod -s /bin/bash apache
這樣就可以apache 就可以使用 at 了
由於at指令不同其他,不能用shell_exec執行,所以用以下方法
<?php
$r = popen('/usr/bin/at noon',"w");
fwrite($r,"ls -l");
pclose($r);
?>
搞定
- Feb 16 Sun 2014 13:27
-
move_uploaded_file gives “failed to open stream: Permission denied ” error
This is because
images and tmp_file_upload are only writable by root user. For upload to work we need to make the owner of those folders same as httpd process owner OR make them globally writable (bad practice).ps aux | grep httpd. The first column will be the owner typically it will be nobodyChange the owner of images and tmp_file_upload to be become nobody or whatever the owner you found in step 1.
$sudo chown nobody /var/www/html/mysite/images/
$sudo chown nobody /var/www/html/mysite/tmp_file_upload/
Chmod images and tmp_file_upload now to be writable by the owner, if needed [Seems you already have this in place]. Mentioned in @Dmitry Teplyakov answer.
$ sudo chmod -R 0755 /var/www/html/mysite/images/
$ sudo chmod -R 0755 /var/www/html/mysite/tmp_file_upload/
For more details why this behavior happend, check the manual http://php.net/manual/en/ini.core.php#ini.upload-tmp-dir , note that it also talking about open_basedir directive.
- Feb 16 Sun 2014 08:31
-
php 上傳多個檔案
上傳多個檔案
可以對 input 功能變數使用不同的 name 來上傳多個檔案。
PHP 支援同時上傳多個檔案並將它們的訊息自動以陣列的形式組織。要完成這項功能,需要在 HTML 表單中對檔案上傳功能變數使用和多選框與復選框相同的陣列式送出語法。
注: 對多檔案上傳的支援是在 PHP 3.0.10 版本增加的。
例子 38-4. 上傳多個檔案
<form action="file-upload.php" method="post" enctype="multipart/form-data"> |
當以上表單被送出後,陣列 $_FILES['userfile'],$_FILES['userfile']['name'] 和 $_FILES['userfile']['size'] 將被起始化(在 PHP 4.1.0 以前版本是 $HTTP_POST_FILES)。若果 register_globals 的設定為 on,則和檔案上傳關聯的全局變量也將被起始化。所有這些送出的訊息都將被儲存到以數字為索引的陣列中。
例如,假設名為 /home/test/review.html 和 /home/test/xwp.out 的檔案被送出,則 $_FILES['userfile']['name'][0] 的值將是 review.html,而 $_FILES['userfile']['name'][1] 的值將是 xwp.out。類似的,$_FILES['userfile']['size'][0] 將包括檔案 review.html 的大小,依此類推。
此外也同時設定了 $_FILES['userfile']['name'][0],$_FILES['userfile']['tmp_name'][0],$_FILES['userfile']['size'][0] 以及 $_FILES['userfile']['type'][0]。
- Feb 09 Sun 2014 19:00
-
php 遞歸 問題
function trim_dom_node($string){
$string=str_replace(" <","<",$string,$count);
echo "com ";
if($count >= 1)
{
trim_dom_node($string);
}
else {return str_replace("\n<","<",$string);}
}
- Feb 04 Tue 2014 15:20
-
php 回覆 xml 格式 資料
header("Content-Type:text/xml");
echo "<
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<g2sResponse xmlns="http://www.gamingstandards.com/wsdl/g2s/v1.0"><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<g2s:g2sMessage xmlns:g2s="http://www.gamingstandards.com/g2s/schemas/v1.0.3">
<g2s:g2sAck g2s:dateTimeSent="'.time_xml().'" g2s:egmId="RBG_1234"
g2s:hostId="2"/>
</g2s:g2sMessage></g2sResponse>
</soap:Body>
</soap:Envelope>
- Feb 03 Mon 2014 15:20
-
PHP 物件導向 設計 Build seven good object-oriented habits in PHP
However, without object-oriented language constructs, a programmer can still introduce OO characteristics into PHP code. It's a tad more difficult and can make the code more difficult to read because it's mixing paradigms (procedural language with pseudo-OO design). OO constructs in PHP code — such as the ability to define and use classes, the ability to build relationships between classes that use inheritance, and the ability to define interfaces — make it much easier to build code that adheres to good OO practices.
While purely procedural designs without much modularity run just fine, the advantages of OO design show up in the maintenance. Because a typical application will spend the bulk of its lifetime in maintenance, code maintenance is a large expense over the lifetime of an application. It can also be easily forgotten during development. If you're in a race to get your application developed and deployed, long-term maintainability can take a back seat to getting something to work.
- Feb 02 Sun 2014 18:58
-
php function 參數 數目 可變
<?php function foo() {
$numargs = func_num_args(); if ($numargs > 2) {
echo "First: ". func_get_arg(0). "\n";
echo "Second: ". func_get_arg(1). "\n";
echo "Third: ". func_get_arg(2). "\n";
} return $numargs;
}
$n = foo (10, 15, 20); //傳入 3 個參數 echo $n; ?>
- Jan 28 Tue 2014 19:45
-
php htmlspecialchars htmlentities 單引號 '
var_dump(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES | ENT_XML1));
The result will look like this:
array(5) {
["""]=>
string(6) """
["&"]=>
string(5) "&"
["'"]=>
string(6) "'"
["<"]=>
string(4) "<"
[">"]=>
string(4) ">"
} echo htmlspecialchars("&<>\"'", ENT_QUOTES | ENT_XML1);
echo html_entity_decode("&<>"'", ENT_QUOTES | ENT_XML1);
http://nikic.github.io/2012/01/28/htmlspecialchars-improvements-in-PHP-5-4.html
- Feb 17 Wed 2010 00:12
-
PHP 如何取得重定向網址 How To Get Redirect URL In PHP
and provide the redirection URL in the “Location” header. I’ve written
three complementary PHP functions that you can use to find out where an
URL redirects to (based on a helpful thread at WebmasterWorld). You don’t even need CURL for this – fsockopen() will do just fine.