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']);
}
}
?>
arrow
arrow
    全站熱搜

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