天天看点

PHP上传类的相关问题

工作任务:FTP模块工作计划

相关文件

  1、表 pureftpd

  2、模块目录ftp,mod/ftp

功能需求

  3、能够批量上传文件

  4、删除目录

----------------------

  1、统计空间的大小,统计的缓存在.ftpquota,格式:文件数量,目录容量

  2、增加ftp,控件 的容量

  3、关闭ftp,mv /file/webroot/91.tc/p/pa/paladin /file/webroot/91.tc/p/pa/paladin.close

  4、删除ftp文件

----------------------------------

写入FLASH的FTP上传控件:

        <table width="90%" align="center" cellpadding="0" cellspacing="0">

        <tr>

          <td height=26 class=font1><strong>图片上传</strong><font color="#FF0000">(可一次性上传1-8张,格式为jpg/gif/png,大小限制为1M,标题为空时取图片文件名)</font></td>

        </tr>

      </table>

   <table width="100%" cellspacing="0" cellpadding="0" align="center">

   <tr>

            <td class="font1" align="center">

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="470" height="350">

        <param name="movie" value="image/upload.swf?sn=PHPSESSID&sid=kbq8j36uo8b7qdmsveksgimlb7&url=http://ggmm.mzod.com/&t=P">

        <param name="quality" value="high">

        <embed src="image/upload.swf?sn=PHPSESSID&sid=kbq8j36uo8b7qdmsveksgimlb7&url=http://ggmm.mzod.com/&t=P" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="470" height="350"></embed>

    </object>

   </td>

  </tr>

  </table>

------------------------- upload.swf

upload.php ------------------------- //flash上传语言

$lang['flash'] = array(

                                        'btn_browse' => '浏览',

                                        'btn_remove' => '移除',

                                        'btn_upload' => '上传',

                                        'btn_close'  => '关闭',

                                        'grid_name'  => '文件名',

                                        'grid_size'  => '大小',

                                        'info_default'     => '选择要上传的文件.',

                                        'info_course'      => '上传进度:',

                                        'info_open_failed' => '文件打开失败.',

                                        'info_success'     => '成功',

                                        'info_failed'      => '失败文件个数',

                                        );   -------------------------------------------------------- <?php

require_once 'class.php';

if(empty($t)){

        $t = "P";

}

echo '<?xml version="1.0" encoding="utf-8"?>

<root>

        <typeList value="' . join($fileType[$t], ",") . '" />

        <lang name="CN">';

        foreach ($lang['flash'] as $key=>$value){

                echo '

                <info id="' . $key . '" value="' . $value . '" />';

        }

echo '

        </lang>

</root>';

?>

/

class FTP {

 // 环境变量

 protected $basedir; // 基础目录;

 protected $usefiles;   // 使用的状态;

 protected $usesize;   // 使用控件; 

 protected $quotafiles; //文件数

 protected $quotasize; //文件大小

 protected $filesize; //上传文件大小 

 function __construct(){

  $this->quotafiles = 1000;

  $this->quotasize  = 1024*1024; 

  $this->basedir  = 'tmp/';

  $this->readuse();

 }

 private function __set($key,$value){

   $this->{$key} = $value;

   if ($key=='basedir'){

    $this->readuse();

   }

 } 

 private function readuse(){         //读出已上传文件配额信息

   $use = File::read($this->basedir.'/info.txt');

   list($files,$size ) = explode(" ", $use);

   $this->usefiles = (int)$files;

   $this->usesize = (int)$size;   

 }

 private function ifover($addfiles,$addsize){           //判断是否超过配额

   if ( $this->usefiles+$addfiles > $this->quotafiles){

    return true;

   }

   if ( $this->usesize+$addsize > $this->quotasize){

    return true;

   }

   return false;

 } 

 private function writeuse($addfiles,$addsize){     //写入已使用的配额

    $this->usesize  += $addsize;

    $this->usefiles += $addfiles;

    $data     = sprintf('%s %s',$this->usefiles,$this->usesize);      

    File::write($this->basedir.'/info.txt',$data); 

 }

 public function upload($objpath,$ctrlname=''){

   $result = false;

   $objpath .= '/';

   if ($ctrlname!=''&& ($files=$_FILES[$ctrlname])){

      if ( is_array($files['name']) ){

       $result = $this->saves($files,$objpath);

      }else{

       $result =$this->save($files,$objpath);

      }

      return $result;

   }

   foreach($_FILES as $files){

      if ( is_array($files['name']) ){

       $result = $this->saves($files,$objpath);

      }else{

       $result = $this->save($files,$objpath);

      }

      if (!$result){

       return $result;

      }

   }

   return  $result;

 }

 protected function save($afileinfo,$objpath,$filename=''){

    $filename == '' && $filename = $afileinfo['name'];

      if ($afileinfo['error']==0){

      if (is_uploaded_file($afileinfo['tmp_name'])){

      $filesize = (int)$afileinfo['size'];   //上传的文件大小

      if ( $this->ifover(1,$filesize) ){

       return false;

      }      

      is_dir($objpath) || Dir::mk($objpath);

      @move_uploaded_file($afileinfo['tmp_name'],$objpath."/$filename");

      $this->writeuse(1,$filesize);

      return true;

      }

      }

      return false;

 } 

 protected function saves($files,$objpath,$filename=''){

   $result = false;

    foreach($files['name'] as $key => $name){

    $afileinfo['name']  = $files['name'][$key];

    $afileinfo['type']   = $files['type'][$key];

    $afileinfo['tmp_name']  = $files['tmp_name'][$key];

    $afileinfo['error']  = $files['error'][$key];

    $afileinfo['size']  = $files['size'][$key];                               

    $result = $this->save($afileinfo,$objpath);

    if (!$result){return false;}

    }

     return false;

 } 

 public function html($uploadpath='/tmp/',$urlpath='/'){

  if ($urlpath == '/'){

   $url =  parse_url($_SERVER['REQUEST_URI']);   

   $url = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="470" height="350">

   <param name="movie" value="'.$flashfile.'">

   <param name="quality" value="high">

   <embed src="'.$flashfile.'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="470" height="350"></embed>

  </object></div>';  

 }

}

?>

?>