您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP实现ftp上传文件示例_PHP

2024/4/12 2:01:19发布16次查看
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权限设置
感兴趣的朋友可以测试运行或改写本文所述代码,加深理解的同时可以让代码功能更加完善。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product