国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHP實現ftp上傳文件示例

2024-05-04 23:25:15
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了PHP實現ftp上傳文件的方法,是非常實用的技巧,需要的朋友可以參考下
 
 

FTP上傳是PHP實現的一個常見且非常重要的應用技巧,今天就來與大家分享一下PHP實現FTP上傳文件的簡單示例。希望對大家的PHP學習能帶來一定的幫助。

主要代碼如下:

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創建目錄make_directory($conn,$path);//利用ftp選擇進入目錄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權限設置

感興趣的朋友可以測試運行或改寫本文所述代碼,加深理解的同時可以讓代碼功能更加完善。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黎川县| 绥芬河市| 临城县| 平凉市| 梅河口市| 河津市| 梁河县| 顺平县| 莎车县| 应城市| 蛟河市| 镶黄旗| 日喀则市| 文昌市| 辽宁省| 奎屯市| 东乡族自治县| 乐山市| 泰宁县| 兴安盟| 井冈山市| 张掖市| 鸡东县| 凌云县| 鹿泉市| 永新县| 泽库县| 富平县| 甘肃省| 合江县| 营口市| 天祝| 璧山县| 大安市| 胶南市| 磴口县| 宣威市| 会同县| 临朐县| 革吉县| 大同县|