无为清净楼资源网 Design By www.qnjia.com
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权限设置
感兴趣的朋友可以测试运行或改写本文所述代码,加深理解的同时可以让代码功能更加完善。
标签:
PHP,ftp,上传,文件
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 群星.1991-不一样的感觉REMIX【宝丽金】【WAV+CUE】
- 银霞.1983-《你那好冷的小手》珍藏纪念版[WAV分轨]
- 银霞.2002-《国语巨星专辑VOL.3》2CD台湾版[WAV+CUE]
- 金池刘罡《昨日情歌HQ》头版限量编号[低速原抓WAV+CUE]
- 段奥娟.2024-23·岁碎念【白米范】【FLAC分轨】
- 顺子.2001-昨日·唯一·更多·顺子自选辑【魔岩】【WAV+CUE】
- 无印良品.1999-私藏三首·原创相对论(EP)【滚石】【WAV+CUE】
- Merryland《Merryland》[FLAC/分轨][170.22MB]
- 庄锭欣 ELKIE《没有你的未来》[320K/MP3][15.78MB]
- 庄锭欣 ELKIE《没有你的未来》[FLAC/分轨][36MB]
- TchaikovskySwanLake,Op.20柴可夫斯基天鹅湖(2013)SACD[Hi-Res]
- 24bit达人艺典《琴歌终极版》整轨WAV+CUE
- 黑鸭子.2005-《发烧DSD》柏菲[WAV分轨]
- 群星.1990-电影看板·人间道【宝丽金】【WAV+CUE】
- 周殷廷.2024-TO.WHOM.IT.MAY.CONCERN【环球】【FLAC分轨】