PHP移動互連網開發筆記(5)——檔案的上傳下載,
原文地址:http://www.php100.com/html/php/rumen/2014/0326/6706.html
一、檔案的上傳
1、用戶端設定:
(1)、在
二、檔案下載
簡單檔案下載只需要使用HTML的連結標記,並將屬性href的URL值指定下載的檔案即可。這種方法只能處理一些瀏覽器不能識別的MIME類型檔案。
為了提高安全性,不希望在a標籤中給出檔案連結,則必須向瀏覽器發送必要的頭資訊,我們可以使用如下代碼。
三、檔案函數庫
touch
設定檔案的訪問和修飾時間
bool touch(string $filename[, int $time[, int $time]])
copy
複製檔案
bool copy(string $source, string $dest)
注意:移動檔案請使用rename函數
file_put_contents
將一個字串寫入檔案
int file_put_contents(string $filename, string $data[, int $flag[, resource $content]])
file_get_contents
將整個檔案讀到字串
string file_get_contents(string $filename[, bool user_include_path [, resource $content[, int $offset[, int $maxlen]]]])
四、序列化與還原序列化
serialize
序列化
string serialize(mixed $value)
注意:serialize()可處理除了resouce之外的任何類型。甚至可以serialize()那些包含了指向其自身引用的數組。
unserialize
還原序列化
mixed unserialize(string $str)
● date
格式化一個本地時間/日期
string date(string format[, int timestamp]);
● getdate
取得日期/時間資訊
array getdate([int timestamp]);
● microtime
返回當前Unix時間戳記和微秒數
mixed microtime([bool get_as_float]);
● date_default_timezone_set
設定預設時區
bool date_default_timezone_set(string timezone_identifier);
● date_default_timezone_get
擷取預設時區
string date_default_timezone_get(void);
三、字元函數庫
strlen
擷取字串長度
int strlen(string $str);
strtolower
字串轉換為小寫
string strtolower(string $str);
strtoupper
字串轉換為大寫
string strtoupper(string $str);
ucfirst
首字母大寫
string ucfirst(string $str);
ucwords
將每個單詞的首字母轉換為大寫字母
string ucwords(string $str);
ltrim
從字串開始的位置刪除空格或其他字元
string ltrim(string $str [, string $charlist]);
rtrim
從字串結束的位置刪除空格或者其他字元
string rtrim(string $str[, string $chirlist]);
trim
從字串開始和結束的位置刪除空格或者其他字元
str_replace
字元替換
mixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count]);
str_ireplace
字元替換
mixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count]);
md5
計算字串的MD5雜湊
string md5(string $str[, bool $raw_output=false]);
strpos
返回一個字元在另一個字元第一次出現的位置
int strpos(string haystack, mixed needle[, int offset]);