目前分類:php (4)

瀏覽方式: 標題列表 簡短摘要
http://www.aditus.nu/jpgraph/
http://a-wei.net/archives/86
http://tech.ddvip.com/2008-10/122449461080346.html

[Mac]
# cd /usr/lib/php
# ln -sf JPGRAPHPATH/src jpgraph
# vi /usr/local/php5/lib/php.ini => include_path = ".:/usr/lib/php/jpgraph"
# /usr/sbin/apachectl restart

# cd /Library/WebServer/Documents
# mkdir jpgraph
# cd jpgraph
# cp -r JPGRAPHPATH/src .
# cp -r JPGRAPHPATH/docportal .

http://localhost/jpgraph/src/Examples/testsuit.php
http://localhost/jpgraph/docs/index.html

For instance,
include ("/Library/WebServer/Documents/jpgraph/src/jpgraph.php");
include ("/Library/WebServer/Documents/jpgraph/src/jpgraph_bar.php");

[Ubuntu]
# cd /usr/lib/php5
# ln -sf JPGRAPHPATH/src jpgraph
# vi /etc/php5/apache2/php.ini => include_path = ".:/usr/share/php:/usr/lib/php5/jpgraph"
# /etc/init.d/apache2 restart
# cd /var/www
# mkdir jpgraph
# cd jpgraph
# ln -sf JPGRAPHPATH/src/Examples .
# ln -sf JPGRAPHPATH/docs .

http://localhost/jpgraph/Examples/testsuit.php
http://localhost/jpgraph/docs/index.html

For instance,
include ("jpgraph.php");
include ("jpgraph_bar.php");

JpGraph Error
Font file "/usr/X11R6/lib/X11/fonts/truetype/verdana.ttf" is not readable or does not exist.
# sudo apt-get install msttcorefonts
# sudo vim JPGRAPHPATH/src/jpg-config.inc.php
DEFINE("TTF_DIR","/usr/share/fonts/truetype/msttcorefonts/");
# /etc/init.d/apache2 restart

REFERENCES:
http://www.binnendijk.net/jpgraph/index.php

wenching520 發表在 痞客邦 留言(0) 人氣()

1.$sCmd = ~YOUR_COMMANDS~ . " >/dev/null 2>&1 & echo \$!";

Here, '>/dev/null 2>&1' means whatever stdout or stderr are piped into /dev/null.

Reference: http://blog.daviesliu.net/2005/08/31/200811/
Linux Shell 環境中支持輸入輸出重定向,用符號<和>來表示。0、1和2分別表示標準輸入、標準輸出和標準錯誤信息輸出。
同時,還可以在這三個標準輸入輸出之間實現重定向,比如將錯誤信息重定向到標準輸出,可以用 2>&1來實現。
Linux下還有一個特殊的文件/dev/null,它就像一個無底洞,所有重定向到它的信息都會消失得無影無蹤。
如果想要正常輸出和錯誤信息都不顯示,則要把標準輸出和標準錯誤都重定向到/dev/null, 例如:
# ls >/dev/null 2>&1
注意:此處的順序不能更改,否則達不到想要的效果,此時先將標準輸出重定向到 /dev/null,然後將標準錯誤重定向到標準輸出,由於標準輸出已經重定向到了/dev/null,因此標準錯誤也會重定向到/dev/null,於是一切靜悄悄:-)

2.exec( $sCmd );

3.echo "<meta http-equiv=\"refresh\" content=\"~DELAY_in_SEC~;url=~Redirect_Location~\">";

wenching520 發表在 痞客邦 留言(0) 人氣()

Create a Project folder in /var/www and put all php files into that folder, and remember to use 'sudo chmod 777 /var/www/ProjectDir -R'.

Q1. When using 'mkdir', we occur "Warning: mkdir() [function.mkdir]: Permission denied in index.php on line 23"
A1. sudo chmod 777

Q2. replace new line '\n' in textarea into '
\n' in HTML
A2.
$message = ereg_replace("\n", "
\n", $sContent );
echo "

$sContent

";
or
echo nl2br( $sContent );

Q3. When using 'rmdir', we occur "Warning: rmdir(/tmp/664838dcfc993201ce07af5bae3ef0da) [function.rmdir]: Directory not empty in index.php on line 54"
A3.
function rmdir_recurse( $file ) {
if( is_dir( $file ) && !is_link( $file ) ) {
foreach( glob( $file . '/*' ) as $sf ) {
if( !rmdir_recurse( $sf ) ) {
echo( "Failed to remove $sf\n" );
return false;
}
}
return rmdir( $file );
}
else {
return unlink( $file );
}
}
and call 'rmdir_recurse( $sJobDir ) or die( "Could not remove $sJobDir.
\n" );'

Q4. Difference btw empty() and isset()
A4.
Example #1 A simple empty() / isset() comparison.
$var = 0;
// Evaluates to true because $var is empty
if (empty($var)) {
echo '$var is either 0, empty, or not set at all';
}
// Evaluates as true because $var is set
if (isset($var)) {
echo '$var is set even though it is empty';
}
?>
Empty():
Returns FALSE if var has a non-empty and non-zero value.
The following things are considered to be empty:
"" (an empty string)
0 (0 as an integer)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a value in a class)

Q5. Error Messages Explained
A5.
http://ca.php.net/features.file-upload.errors
http://php.chinaunix.net/manual/zh/features.file-upload.errors.php
從 PHP 4.2.0 開始,PHP 將隨文件信息數組一起返回一個對應的錯誤代碼。該代碼可以在文件上傳時生成的文件數組中的 error 字段中被找到,也就是 $_FILES['userfile']['error']。
UPLOAD_ERR_OK
其值為 0,沒有錯誤發生,文件上傳成功。
UPLOAD_ERR_INI_SIZE
其值為 1,上傳的文件超過了 php.ini 中 upload_max_filesize 選項限制的值。
UPLOAD_ERR_FORM_SIZE
其值為 2,上傳文件的大小超過了 HTML 表單中 MAX_FILE_SIZE 選項指定的值。
UPLOAD_ERR_PARTIAL
其值為 3,文件只有部分被上傳。
UPLOAD_ERR_NO_FILE
其值為 4,沒有文件被上傳。
UPLOAD_ERR_NO_TMP_DIR
其值為 6,找不到臨時文件夾。PHP 4.3.10 和 PHP 5.0.3 引進。
UPLOAD_ERR_CANT_WRITE
其值為 7,文件寫入失敗。PHP 5.1.0 引進。
Note: 以上值在 PHP 4.3.0 之後變成了 PHP 常量。

If a new error constant would be introduced, your script would ignore it and assume that the upload went OK.
Anonymous has included a better version below:
$uploadErrors = array(
UPLOAD_ERR_OK => 'There is no error, the file uploaded with success.',
UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded.',
UPLOAD_ERR_NO_FILE => 'No file was uploaded.',
UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder.',
UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.',
UPLOAD_ERR_EXTENSION => 'File upload stopped by extension.',
);

$errorCode = $_FILES['myUpload']['error'];

if($errorCode !== UPLOAD_ERR_OK && isset($uploadErrors[$errorCode]))
{
throw new Exception($uploadErrors[$errorCode]);
}
?>

For a multifile upload try this:
foreach($_FILES as $file)
{
if($file['error'] == 0 && $file['size'] > 0)
{
move_uploaded_file($file['tmp_name'], $targetdir.$file['name']);
}
}
?>

wenching520 發表在 痞客邦 留言(0) 人氣()

http://blog.roodo.com/jaceju/archives/805389.html

php code:
$file_name = "file.name";
$file_path = "/path/to/realfile";
$file_size = filesize($file_path);
header('Pragma: public');
header('Expires: 0');
header('Last-Modified: ' . gmdate('D, d M Y H:i ') . ' GMT');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/octet-stream');
header('Content-Length: ' . $file_size);
header('Content-Disposition: attachment; filename="' . $file_name . '";');
header('Content-Transfer-Encoding: binary');
readfile($file_path);

wenching520 發表在 痞客邦 留言(0) 人氣()