PHP實(shí)現(xiàn)ftp上傳文件示例
更新時(shí)間:2014年08月21日 14:46:31 投稿:shichen2014
這篇文章主要介紹了PHP實(shí)現(xiàn)ftp上傳文件的方法,是非常實(shí)用的技巧,需要的朋友可以參考下
FTP上傳是PHP實(shí)現(xiàn)的一個(gè)常見且非常重要的應(yīng)用技巧,今天就來與大家分享一下PHP實(shí)現(xiàn)FTP上傳文件的簡單示例。希望對大家的PHP學(xué)習(xí)能帶來一定的幫助。
主要代碼如下:
function make_directory($ftp_stream, $dir){ // if directory already exists or can be immediately created return true if ($this->ftp_is_dir($ftp_stream, $dir) || @ftp_mkdir($ftp_stream, $dir)) return true; // otherwise recursively try to make the directory if (!$this->make_directory($ftp_stream, dirname($dir))) return false; // final step to create the directory return ftp_mkdir($ftp_stream, $dir); } function ftp_is_dir($ftp_stream, $dir){ // get current directory $original_directory = ftp_pwd($ftp_stream); // test if you can change directory to $dir // suppress errors in case $dir is not a file or not a directory if ( @ftp_chdir( $ftp_stream, $dir ) ) { // If it is a directory, then change the directory back to the original directory ftp_chdir( $ftp_stream, $original_directory ); return true; } else { return false; } } $conn = ftp_connect("ftp地址") or die("Could not connect"); ftp_login($conn,"ftpname","password"); //利用ftp創(chuàng)建目錄 make_directory($conn,$path); //利用ftp選擇進(jìn)入目錄 ftp_chdir($conn,$path); //開始上傳 if(ftp_put($conn,$info[0]['savename'],getcwd().$upload->savePath.$info[0]['savename'],FTP_BINARY)){ unlink(getcwd().$upload->savePath.$info[0]['savename']); } ftp_close($conn); //注意上傳端的ftp權(quán)限設(shè)置
感興趣的朋友可以測試運(yùn)行或改寫本文所述代碼,加深理解的同時(shí)可以讓代碼功能更加完善。
相關(guān)文章
mayfish 數(shù)據(jù)入庫驗(yàn)證代碼
mayfish 可以靈活的自定義將要執(zhí)行寫入的數(shù)據(jù)內(nèi)容的校驗(yàn)規(guī)則,以減少開發(fā)人員手動對每一個(gè)字段的數(shù)據(jù)進(jìn)行校驗(yàn)的麻煩。2010-04-04PHP實(shí)現(xiàn)PDO的mysql數(shù)據(jù)庫操作類
這篇文章主要介紹了PHP實(shí)現(xiàn)PDO的mysql數(shù)據(jù)庫操作類,其中dbconfig類負(fù)責(zé)配置數(shù)據(jù)庫訪問信息,dbtemplate類集合了對數(shù)據(jù)庫的訪問操作,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-12-12

一文解決PHP中生成隨機(jī)數(shù)遇到的重復(fù)問題
項(xiàng)目開發(fā)中很多地方需要用到唯一編碼,比如說訂單、卡券、邀請碼等等,這些編號是需要嚴(yán)格保證唯一性的,因?yàn)槿绻到y(tǒng)中訂單的編號存在倆一模一樣的,那造成很多數(shù)據(jù)的錯亂,所以本文給大家介紹了如何解決PHP中生成隨機(jī)數(shù)遇到的重復(fù)問,需要的朋友可以參考下
2023-12-12