搜尋
首頁後端開發php教程web方式ftp,建议加入精华区,嘿嘿_PHP


/* $Id: ftp.php,v 2.2 2002/03/12 23:21:28 pauls Exp $ */

/* This software came from http://inebria.com/ */

/* Copyright (c) 2000
      Paul Southworth.  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote
    products derived from this software without specific prior
    written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

/* Configuration Options */

$phpftp_host="localhost";
$phpftp_version="2.2";

/* Comment this out if you don't want the version footer */

$show_version_footer=1;

/* How large a file will you accept?  You may also need to edit your
   php.ini file and change upload_max_filesize appropriately */

$max_file_size="1000000";

/* The temporary directory $phpftp_tmpdir must exist and be writable
   by your web server.
   Hint:  mkdir /var/tmp/xfers && chmod 1777 /var/tmp/xfers */

$phpftp_tmpdir="/var/tmp/xfers";

/* $use_mime_lookup
   Turning this on creates a dependency upon the
   http://www.inebria.com/mime_lookup/ MIME type lookup library.
   Setting this variable to "1" enables it.  "0" disables.
   If you turn it on, put the mime_lookup.php file in the same directory
   as ftp.php and uncomment the 'include("mime_lookup.php");' statement. */

$use_mime_lookup="0";
/* include("mime_lookup.php"); */

/* We enclose the top and bottom in functions because sometimes
   we might not send them (ie, in a file-download situation) */

function phpftp_top() {
    global $phpftp_version;
?>



PHP FTP Client <?php echo $phpftp_version; ?>


}

function phpftp_bottom() {
    global $phpftp_version;
    global $show_version_footer;
?>

if (isset($show_version_footer)) {
?>

This is PHP FTP
version


}
?>


}

/* This is the form used for initially collecting username/passwd */

function phpftp_login() {
    phpftp_top();
?>








Login:



Password:



Directory:









    phpftp_bottom();
}

/* This function does not return TRUE/FALSE - it returns the value of
   $ftp, the current FTP stream. */

function phpftp_connect($phpftp_user,$phpftp_passwd) {
    global $phpftp_host;
    $ftp = ftp_connect($phpftp_host);
    if ($ftp) {
        if (ftp_login($ftp,$phpftp_user,urldecode($phpftp_passwd))) {
            return $ftp;
        }
    }
}

function phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir) {
    global $phpftp_host;
    phpftp_top();
?>

    $ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);
    if (!$ftp) {
?>
FTP login failed!
Start over?
        phpftp_bottom();
    } else {
        if (!$phpftp_dir) {
            $phpftp_dir=ftp_pwd($ftp);
        }
        if (!@ftp_chdir($ftp,$phpftp_dir)) {
?>
Can't enter that directory!


            $phpftp_dir=ftp_pwd($ftp);
        }
        echo "Current host: " . $phpftp_host . "
\n";
        echo "Current directory: " . $phpftp_dir . "
\n";
        if ($phpftp_dir == "/") {
            $phpftp_dir="";
        }

        if ($contents = ftp_rawlist($ftp,"")) {
            $d_i=0;
            $f_i=0;
            $l_i=0;
            $i=0;
            while ($contents[$i]) {
                $item[] = split("[ ]+",$contents[$i],9);
                $item_type=substr($item[$i][0],0,1);
                if ($item_type == "d") {
                    /* it's a directory */
                    $nlist_dirs[$d_i]=$item[$i][8];
                    $d_i++;
                } elseif ($item_type == "l") {
                    /* it's a symlink */
                    $nlist_links[$l_i]=$item[$i][8];
                    $l_i++;
                } elseif ($item_type == "-") {
                    /* it's a file */
                    $nlist_files[$f_i]=$item[$i][8];
                    $nlist_filesize[$f_i]=$item[$i][4];
                    $f_i++;
                } elseif ($item_type == "+") {
                    /* it's something on an anonftp server */
                    $eplf=split(",",implode(" ",$item[$i]),5);
                    if ($eplf[2] == "r") {
                        /* it's a file */
                        $nlist_files[$f_i]=trim($eplf[4]);
                        $nlist_filesize[$f_i]=substr($eplf[3],1);
                        $f_i++;
                    } elseif ($eplf[2] == "/") {
                        /* it's a directory */
                        $nlist_dirs[$d_i]=trim($eplf[3]);
                        $d_i++;
                    }
                } /* ignore all others */
                $i++;
            }
?>


            if (count($nlist_dirs)>0) {
?>

            }

            if (count($nlist_files)>0) {
?>

            }
        } else {
?>

Directory empty or not readable


        }
?>


Directories











Files













        $cdup=dirname($phpftp_dir);
        if ($cdup == "") {
            $cdup="/";
        }
?>
























        ftp_quit($ftp);
        phpftp_bottom();
    }
}

function phpftp_cd($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_directory) {
?>

    $new_directory=$phpftp_dir . "/" . $select_directory;
    phpftp_list($phpftp_user,$phpftp_passwd,$new_directory);
}

function phpftp_mkdir($phpftp_user,$phpftp_passwd,$phpftp_dir,$new_dir) {
?>

    $ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);
    if ($phpftp_dir == "") {
        $phpftp_dir="/";
    }
    if (!$ftp) {
        @ftp_quit($ftp);
        phpftp_top();
?>
FTP login failed!


Start over?
        phpftp_bottom();
    } else {
        $dir_path = $phpftp_dir . "/" . $new_dir;
        @ftp_mkdir($ftp,$dir_path);
        @ftp_quit($ftp);
        phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);
    }
};
    

function phpftp_get($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file) {
    $ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);
    if ($phpftp_dir == "") {
        $phpftp_dir="/";
    }
    if ((!$ftp) || (!@ftp_chdir($ftp,$phpftp_dir))) {
        @ftp_quit($ftp);
        phpftp_top();
?>
FTP login failed!


Start over?
        phpftp_bottom();
    } else {
        srand((double)microtime()*1000000);
        $randval = rand();
        $tmpfile=$phpftp_tmpdir . "/" . $select_file . "." . $randval;
        if (!ftp_get($ftp,$tmpfile,$select_file,FTP_BINARY)) {
            ftp_quit($ftp);
            phpftp_top();
?>
FTP get failed!


Start over?
            phpftp_bottom();
        } else {
            ftp_quit($ftp);
            global $use_mime_lookup;
            if ($use_mime_lookup == "1") {
                $file_mime_type=mime_lookup(substr(strrchr($select_file,"."),1));
            }
            if (!$file_mime_type) {
                $file_mime_type="application/octet-stream";
            }
            header("Content-Type: " . $file_mime_type);
            header("Content-Disposition: attachment; filename=" . $select_file);
            readfile($tmpfile);
        }
        @unlink($tmpfile);
    }
}

function phpftp_put($phpftp_user,$phpftp_passwd,$phpftp_dir,$userfile,$userfile_name) {
    srand((double)microtime()*1000000);
    $randval = rand();
    $tmpfile=$phpftp_tmpdir . "/" . $userfile_name . "." . $randval;
    if (!@move_uploaded_file($userfile,$tmpfile)) {
        phpftp_top();
?>
Upload failed!  Can't create temp file?


Start over?
        phpftp_bottom();
    } else {
        if (!$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd)) {
            unlink($tmpfile);
            phpftp_top();
?>
FTP login failed!


Start over?
            phpftp_bottom();
        } else {
            ftp_chdir($ftp,$phpftp_dir);
            ftp_put($ftp,$userfile_name,$tmpfile,FTP_BINARY);
            ftp_quit($ftp);
            unlink($tmpfile);
            phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);
        }
    }
}

switch($function) {
    case "dir";
        phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);
        break;
    case "cd";
        phpftp_cd($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_directory);
        break;
    case "get";
        phpftp_get($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file);
        break;
    case "put";
        phpftp_put($phpftp_user,$phpftp_passwd,$phpftp_dir,$userfile,$userfile_name);
        break;
    case "mkdir";
        phpftp_mkdir($phpftp_user,$phpftp_passwd,$phpftp_dir,$new_dir);
        break;
    case "";
        phpftp_login();
        break;
}

?>

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
百度网盘群怎么加入百度网盘群怎么加入Feb 23, 2024 pm 01:46 PM

百度网盘群怎么加入?百度网盘中是可以加入到群聊,但是多数的小伙伴不知道百度网盘中如何加入到群聊中,接下来就是小编为用户带来的百度网盘群加入方法图文教程,感兴趣的用户快来一起看看吧!百度网盘群怎么加入1、首先打开百度网盘APP,主页面底部【共享】点击进入专区;2、然后在下图所示共享界面,点击右上角【+】号;3、之后下方展开窗口,选择【加好友/群】功能;4、最后输入群账号或者扫一扫都可以添加群聊。

php怎么设置implode没有分隔符php怎么设置implode没有分隔符Apr 18, 2022 pm 05:39 PM

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

win11canary渠道怎么加入win11canary渠道怎么加入Feb 11, 2024 pm 07:12 PM

很多小伙伴们在看了微软最新颁布的预览版的介绍以后,都想着怎么才能加入到这个预览版的下载中的呢,今天小编就开来和大家说一说这个问题吧。win11canary渠道怎么加入1、首先我们点击电脑底部的开始菜单,然后我们找设置按钮。2、随后我们在设置页面中,找到windows更新,在点击windows预览体验计划。3、我们进入到这个页面以后,找到右边的canary渠道,点击加入即可。

行侠仗义五千年门派加入顺序行侠仗义五千年门派加入顺序Mar 23, 2024 pm 12:50 PM

行侠仗义五千年有很多各种各样的门派,每一个门派都可以加入,有很多玩家想知道门派加入顺序是什么,小编按照学不学习龙象之力将门派加入顺序总结出来了,一起来看看这篇行侠仗义五千年门派加入顺序推荐攻略。行侠仗义五千年门派加入顺序1、学习龙象之力推荐顺序:桃花谷>丐帮>峨嵋>少林>华山>紫禁之巅>神墓>密教>武当>移花>星宿>昆仑>其他。解析:推荐想要学习龙象之力的玩家按照这个顺序加入。2、不学龙象之力推荐顺序:桃花谷>丐帮>峨嵋&

Go 语言中的时间处理方式有哪些?Go 语言中的时间处理方式有哪些?Jun 10, 2023 pm 09:42 PM

Go语言作为一个现代化的编程语言,时间在开发中占有很重要的位置。Go语言提供了一些内置的时间函数和结构体,使得时间的处理变得更加便捷。在本篇文章中,将会介绍一些Go语言中常用的时间处理方式。time.Now()我们可以使用time.Now()函数获取当前的时间:now:=time.Now()fmt.Println(now)输出:2019-06-131

升级到Win11 - 2022年是否明智?升级到Win11 - 2022年是否明智?Jan 04, 2024 pm 10:58 PM

距离Win11系统发布已经过去了一年的时间,许多人一直想知道2022年是否建议升级至Win11。实际上,如果我们目前使用的系统感觉良好并且没有遇到任何问题,那么升级并不是必须的。答:2022年不建议升级win11,因为现在win11相比win11并没有多少提升。如果我们喜欢Win11的全新界面和设置,不妨下载来试试看看。1、现在win11和win10的软件兼容性没啥区别,能在win11用的win10也能用。2、如果我们习惯了win10操作的话,win11可能还用着不习惯,很多功能找不到。3、例如

PHP 错误处理:最佳实践和建议PHP 错误处理:最佳实践和建议Aug 07, 2023 pm 12:25 PM

PHP错误处理:最佳实践和建议在编写PHP代码时,错误处理是一项非常重要的任务。如果不正确地处理错误,就会导致应用程序中的漏洞和安全问题。同时,良好的错误处理还有助于提高代码的可维护性和可扩展性。本文将介绍一些PHP错误处理的最佳实践和建议,并提供一些代码示例。使用异常处理在PHP中,异常是一种用于处理运行时错误的机制。通过使用异常,可以将错误

C++开发建议:如何进行模块化的C++开发C++开发建议:如何进行模块化的C++开发Nov 23, 2023 am 08:56 AM

C++语言作为一种通用的高级编程语言,被广泛用于开发各种应用程序和系统。然而,C++的复杂性和灵活性也使得开发人员面临着一些挑战,特别是在大型项目中。在处理大型项目时,模块化的开发方法是至关重要的。本文将介绍如何进行模块化的C++开发,并提供一些建议和最佳实践。模块化开发是指将一个大型项目划分为多个小模块,每个模块有自己的功能和职责,通过模块间的接口进行通信

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前By尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中