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

php ftp文件上传

2025/8/1 2:38:23发布13次查看
function copyviaftprecursively($uploadlocation, $previewpath, $remotedirectory, $ftptype)
        {
        $errormessage = '';
        $connectionid = getftpconnection($uploadlocation['host'], $uploadlocation['username'], $uploadlocation['password'], $uploadlocation['port']);
        switch($ftptype)
                {
                case 'active':
                        ftp_pasv($connectionid, false);
                        break;
                case 'passive':
                        ftp_pasv($connectionid, true);
                        break;
                }
        $basedirectory = $uploadlocation['basedirectory'];
        if(substr($basedirectory, strlen($basedirectory) - 1, 1) != '/')
                {
                $basedirectory .= '/';
                }
        ftp_mkdir($connectionid, $basedirectory); // no point showing an error message if the directory exists (most likely cause of error) because it will exist (at least) after the first time.
        $remotebasedirectory = $basedirectory.$remotedirectory;
        if(substr($remotebasedirectory, strlen($remotebasedirectory) - 1, 1) == '/')
                {
                $remotebasedirectory = substr($remotebasedirectory, 0, strlen($remotebasedirectory) - 1);
                }
        $remotebasedirectory .= '/';
        $errormessage .= copyfileviaftp($previewpath, $remotebasedirectory, $connectionid);
        ftp_close($connectionid);
        $errorhtml = '';
        if($errormessage)
                {
                $errorhtml = nl2br($errormessage);
                }
        return $errorhtml;
        }
function getftpconnection($host, $username, $password, $port)
        {
        $connectionid = ftp_connect($host);
        if(!@ftp_login($connectionid, $username, $password))
                {
                webserviceerror('ftp error. unable to connect to '.$host.' with username '.$username.'');
                }
        return $connectionid;
        }
function copyfileviaftp($sourcepath, $destinationpath, $connectionid)
        {
        $errormessage = '';
        $sourcepath = str_replace( , -, $sourcepath);
        $destinationpath = str_replace( , -, $destinationpath);
        if(!ftp_mkdir($connectionid, $destinationpath))
                {
                $errormessage .= unable to create directory at .$destinationpath. (it may already exist) ;
                }
        ftp_site($connectionid, 'chmod 0777 '.$destinationpath);
        ftp_chdir($connectionid, $destinationpath);
        //print $sourcepath.' to '.$destinationpath.
;
        if(is_dir($sourcepath))
                {
                chdir($sourcepath);
                $handle=opendir('.');
                while(($file = readdir($handle))!==false)
                        {
                        if(($file != .) && ($file != ..))
                                {
                                if(is_dir($file))
                                        {
                                        $errormessage .= copyfileviaftp($sourcepath.directory_separator.$file, $file, $connectionid);
                                        chdir($sourcepath);
                                        if(!ftp_cdup($connectionid))
                                                {
                                                $errormessage .= unable to ftp_cdup. ;
                                                }
                                        }
                                else
                                        {
                                        if(substr($file, strlen($file) - 4, 4) != .zip)
                                                {
                                                $fp = fopen($file,r);
                                                if(!ftp_fput($connectionid, str_replace( , _, $file), $fp, ftp_binary))
                                                        {
                                                        $errormessage .= unable to ftp_fput(). ;
                                                        }
                                                ftp_site($connectionid, 'chmod 0755 '.str_replace( , _, $file));
                                                }
                                        }
                                }
                        }
                closedir($handle);
                }
        return $errormessage;
        }
该用户其它信息

VIP推荐

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