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%" border="0" 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%" border="0" 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>';
?>

//*********** PHP上传类  ***************

<?php
* palaa.org *
* @classfilename FTP.class.php 
* @classname FTP
* @classpath @mod/ftp/
* @memo      FTP类 ,用于FTP文件上传
***********************************************************/

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>';  

 }

}

?>

/******************  测试类 *******************

<?php
class testftp extends UnitTestCase {
  function __construct(){
   $this->UnitTestCase("this test ftp file upload !");
  }
  
  function setUp() {
    $ftp = & new  FTP();
    echo($ftp->html('tmp/'));  
  }
  function test_Xftp(){
    $ftp = & new  FTP();  
    $ftp->upload(ROOT.'tmp/'.$_GET['path']);
    
  }
/*  
// 用于第一次调试的初步测试,不使用flash控件 
 function setUp() {
   print <<<EOT
     <center>
     <div>
     <form action="" method="post" enctype="multipart/form-data" >
      <input type="hidden" name="upload" value="1">
      <p>上传文件
      <p>
       <input type="file" name="file1"><br>
       <input type="file" name="file2[]"><br>
       <input type="file" name="file2[]"><br>
       <input type="file" name="file2[]"><br>
       <input type="file" name="file3[]"><br>
       <input type="file" name="file3[]"><br>
       <input type="file" name="file4[]"><br>
       <input type="file" name="file4[]"><br><br>
       <input type="submit" value="Send" />
      </p>
     </form>
     </div>
     </center> 
EOT;
  }
  function test_Xftp(){
    $ftp = & new  FTP();
    $ftp->upload(ROOT.'tmp/');
    e($_FILES);
    
  }
*/


?> 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值