<?class cUpLoad{var $port;//端口
var $ftp_stream;//开通的ftp的连线代码
var $remote_file;//欲获取的文件名
var $host;//服务器地址
var $username;//合法的用户名
var $password;//密码
var $ftp_pwd;//目前所在的路径
var $directory;//欲前往的路径
var $res;//布尔值
var $arrFileName;//以数组形式取得文件名function cUpLoad(){ //构造函数,完成必要的设定,并且打开ftp的连接

$this->host='localhost';
$this->port=21;
$this->username='danfeng';
$this->password='tangyanyan';
$this->ftp_stream=ftp_connect($this->host) or die ('Database error');
$this->res=ftp_login($this->ftp_stream,$this->username,$this->password) or die ('Database error');}
function UpLoad ($FileName,$File){ //参数分别为欲保存的文件名,目标文件的路径,实现上传功能
if ($this->res) {
if (ftp_put($this->ftp_stream,$FileName,$File,FTP_ASCII)) {

return true;
} else {

return false;
} }}
function FtpFileSize($FileName){ //服务器上指定文件的大小
return ftp_size($this->ftp_stream,$FileName);
}
function ChangeDirectory($directory){  //改变路径(只能打开ROOT下“一”级且已经存在的文件夹的)
return @ftp_chdir($this->ftp_stream,$directory);
}
function FtpFileDelete($FileName) { //删除服务器上指定的文件
 return ftp_delete($this->ftp_stream,$FileName);
}function arrFetchFileName($directory){ //取得ftp路径下的文件,返回一个二维数组
$this->arrFileName=ftp_nlist($this->ftp_stream,$directory);
}function MakeDir($directory){//建立文件夹
return ftp_mkdir($this->ftp_stream,$directory);
}function FtpQuit(){ //断开ftp连线
if(ftp_quit($this->ftp_stream)) {
return true;
} else { 
return false;
}
}} //end class?>

解决方案 »

  1.   

    PHP_Manual原文:POST method uploadsPHP is capable of receiving file uploads from any RFC-1867 compliant browser (which includes Netscape Navigator 3 or later, Microsoft Internet Explorer 3 with a patch from Microsoft, or later without a patch). This feature lets people upload both text and binary files. With PHP's authentication and file manipulation functions, you have full control over who is allowed to upload and what is to be done with the file once it has been uploaded. Note that PHP also supports PUT-method file uploads as used by Netscape Composer and W3C's Amaya clients. See the PUT Method Support for more details. A file upload screen can be built by creating a special form which looks something like this: Example 19-1. File Upload Form<FORM ENCTYPE="multipart/form-data" ACTION="_URL_" METHOD=POST>
    <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000">
    Send this file: <INPUT NAME="userfile" TYPE="file">
    <INPUT TYPE="submit" VALUE="Send File">
    </FORM>
         
     
     
    The _URL_ should point to a PHP file. The MAX_FILE_SIZE hidden field must precede the file input field and its value is the maximum filesize accepted. The value is in bytes. In PHP 3, the following variables will be defined within the destination script upon a successful upload, assuming that register_globals is turned on in php3.ini. If track_vars is turned on, they will also be available in PHP 3 within the global array $HTTP_POST_VARS. Note that the following variable names assume the use of the file upload name 'userfile', as used in the example above: 
    $userfile - The temporary filename in which the uploaded file was stored on the server machine. $userfile_name - The original name or path of the file on the sender's system. $userfile_size - The size of the uploaded file in bytes. $userfile_type - The mime type of the file if the browser provided this information. An example would be "image/gif". Note that the "$userfile" part of the above variables is whatever the name of the INPUT field of TYPE=file is in the upload form. In the above upload form example, we chose to call it "userfile" In PHP 4, the behaviour is slightly different, in that the new global array $HTTP_POST_FILES is provided to contain the uploaded file information. This is still only available if track_vars is turned on, but track_vars is always turned on in versions of PHP after PHP 4.0.2. The contents of $HTTP_POST_FILES are as follows. Note that this assumes the use of the file upload name 'userfile', as used in the example above: 
    $HTTP_POST_FILES['userfile']['name']
    The original name of the file on the client machine. $HTTP_POST_FILES['userfile']['type']
    The mime type of the file, if the browser provided this information. An example would be "image/gif". $HTTP_POST_FILES['userfile']['size']
    The size, in bytes, of the uploaded file. $HTTP_POST_FILES['userfile']['tmp_name']
    The temporary filename of the file in which the uploaded file was stored on the server. 
    Files will by default be stored in the server's default temporary directory, unless another location has been given with the upload_tmp_dir directive in php.ini. The server's default directory can be changed by setting the environment variable TMPDIR in the environment in which PHP runs. Setting it using putenv() from within a PHP script will not work. This environment variable can also be used to make sure that other operations are working on uploaded files, as well. Example 19-2. Validating file uploadsThe following examples are for versions of PHP 3 greater than 3.0.16, and versions of PHP 4 greater than 4.0.2. See the function entries for is_uploaded_file() and move_uploaded_file(). <?php 
    if (is_uploaded_file($userfile)) {
        copy($userfile, "/place/to/put/uploaded/file");
    } else {
        echo "Possible file upload attack: filename '$userfile'.";
    }
    /* ...or... */
    move_uploaded_file($userfile, "/place/to/put/uploaded/file");
    ?>
         
     For earlier versions of PHP, you'll need to do something like the following. Note: This will not work in versions of PHP 4 after 4.0.2. It depends on internal functionality of PHP which changed after that version. 
    <?php 
    /* Userland test for uploaded file. */ 
    function is_uploaded_file($filename) {
        if (!$tmp_file = get_cfg_var('upload_tmp_dir')) {
            $tmp_file = dirname(tempnam('', ''));
        }
        $tmp_file .= '/' . basename($filename);
        /* User might have trailing slash in php.ini... */
        return (ereg_replace('/+', '/', $tmp_file) == $filename);
    }if (is_uploaded_file($userfile)) {
        copy($userfile, "/place/to/put/uploaded/file");
    } else {
        echo "Possible file upload attack: filename '$userfile'.";
    }
    ?>
         
     
     
    The PHP script which receives the uploaded file should implement whatever logic is necessary for determining what should be done with the uploaded file. You can for example use the $file_size variable to throw away any files that are either too small or too big. You could use the $file_type variable to throw away any files that didn't match a certain type criteria. Whatever the logic, you should either delete the file from the temporary directory or move it elsewhere. The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.