Lambda-lib
[ class tree: Lambda-lib ] [ index: Lambda-lib ] [ all elements ]

Class: Upload

Source Location: /libs/Upload.php

Class Overview


アップロード class


Author(s):

  • rooth

Version:

  • 0.0.1

    PHP version 5

     usage:
    
      [html]
       
    
       
       <form method="post" action="..." enctype="multipart/form-data"> // enctype の書き忘れに注意。
       <input type="file" name="upload_document[1]" />
       <input type="file" name="upload_image[1]" />
       <input type="file" name="upload_image[2]" />
       <input type="file" name="upload_image[3]" />
    
      [php]
       require_once '/path/to/Upload.php';
    
       $params = array();
       $params['upload_document'][1] = array('ワードなどの原稿', 2, 'MB');
       $params['upload_image'][1]    = array('画像1', 100, 'KB', '/^(gif|png|jpe?g)$/i');
       $params['upload_image'][2]    = array('画像2', 1, 'MB', '/^(gif|png|jpe?g)$/i');
       $params['upload_image'][3]    = array('画像3', 1, 'MB', '/^(gif|png|jpe?g)$/i');
    
       $upload = new Upload($params);
    
       // アップロード関連の設定を表示
       $upload->getInfo();
    
       $upload->setUploadDir('/path/to/upload');
    
       // (optional) yyyymmdd形式のサブディレクトリを生成する
       $upload->setUploadDir('/path/to/upload')->subDir('%yyyymmdd%');
    
       // (optional) 名前を指定してサブディレクトリを生成する
       $upload->setUploadDir('/path/to/upload')->subDir('subdirname');
    
       if ($upload->execute() === false) {
           echo $upload->getErrMsg();
       } else {
           var_dump($upload->getResults());
       }
    
       array(1) {
         [0]=>
         array(3) {
           ["fieldlabel"]=>
           string(13) "画像1"
           ["orig_filename"]=>
           string(49) "画像1.jpg"
           ["filename"]=>
           string(35) "20090406_123527_upload_image_1_1214.jpg"
           ["filepath"]=>
           string(90) "/path/to/upload/20090406_123527_upload_image_1_1214.jpg"
         }
         [1]=>
         array(3) {
         }
         :
         :
       }

Variables

Constants

Methods



Class Details

[line 109]
アップロード class



Tags:

author:  rooth
version:  

0.0.1

PHP version 5

 usage:

  [html]
   

   
   <form method="post" action="..." enctype="multipart/form-data"> // enctype の書き忘れに注意。
   <input type="file" name="upload_document[1]" />
   <input type="file" name="upload_image[1]" />
   <input type="file" name="upload_image[2]" />
   <input type="file" name="upload_image[3]" />

  [php]
   require_once '/path/to/Upload.php';

   $params = array();
   $params['upload_document'][1] = array('ワードなどの原稿', 2, 'MB');
   $params['upload_image'][1]    = array('画像1', 100, 'KB', '/^(gif|png|jpe?g)$/i');
   $params['upload_image'][2]    = array('画像2', 1, 'MB', '/^(gif|png|jpe?g)$/i');
   $params['upload_image'][3]    = array('画像3', 1, 'MB', '/^(gif|png|jpe?g)$/i');

   $upload = new Upload($params);

   // アップロード関連の設定を表示
   $upload->getInfo();

   $upload->setUploadDir('/path/to/upload');

   // (optional) yyyymmdd形式のサブディレクトリを生成する
   $upload->setUploadDir('/path/to/upload')->subDir('%yyyymmdd%');

   // (optional) 名前を指定してサブディレクトリを生成する
   $upload->setUploadDir('/path/to/upload')->subDir('subdirname');

   if ($upload->execute() === false) {
       echo $upload->getErrMsg();
   } else {
       var_dump($upload->getResults());
   }

   array(1) {
     [0]=>
     array(3) {
       ["fieldlabel"]=>
       string(13) "画像1"
       ["orig_filename"]=>
       string(49) "画像1.jpg"
       ["filename"]=>
       string(35) "20090406_123527_upload_image_1_1214.jpg"
       ["filepath"]=>
       string(90) "/path/to/upload/20090406_123527_upload_image_1_1214.jpg"
     }
     [1]=>
     array(3) {
     }
     :
     :
   }



[ Top ]


Class Variables

$err_msg =  ''

[line 115]



Tags:

access:  protected

Type:   mixed


[ Top ]

$params = array()

[line 111]



Tags:

access:  protected

Type:   mixed


[ Top ]

$results = array()

[line 116]



Tags:

access:  protected

Type:   mixed


[ Top ]

$sub_dir =  ''

[line 113]



Tags:

access:  protected

Type:   mixed


[ Top ]

$upload_dir =  ''

[line 112]



Tags:

access:  protected

Type:   mixed


[ Top ]



Class Methods


static method getBytes [line 344]

static integer getBytes( string $unit)



Tags:

return:  バイト数
access:  protected


Parameters:

string   $unit   単位 {KB|MB}

[ Top ]

static method getExtension [line 325]

static string getExtension( string $fname, [boot $append_dot = false])

拡張子 返却



Tags:

return:  拡張子
access:  protected


Parameters:

string   $fname   ファイル名
boot   $append_dot   ドットを付けるか返却するか否か

[ Top ]

constructor __construct [line 131]

Upload __construct( $params)



Tags:

access:  public


Parameters:

array   $params  

[ Top ]

method execute [line 170]

成功: execute( )



Tags:

return:  array array(array(fieldlabel, orig_filename, filename, filepath), ...) 失敗: bool false
access:  public


[ Top ]

method getErrMsg [line 281]

void getErrMsg( )



Tags:

access:  public


[ Top ]

method getInfo [line 151]

void getInfo( )



Tags:

access:  public


[ Top ]

method getResults [line 289]

void getResults( )



Tags:

access:  public


[ Top ]

method remove [line 299]

void remove( $arr)



Tags:

access:  protected


Parameters:

array   $arr   array(fieldlabel, orig_filename, filename, filepath);

[ Top ]

method save [line 199]

array save( array $key, $idx, $param)



Tags:

return:  array(status, フィールドラベル, オリジナルファイル名, ファイル名, ファイルパス)
access:  protected


Parameters:

array   $key   array(ファイル名, 配列キー, array(フィールドラベル, 最大ファイルサイズ, 許可する拡張子の正規表現))
   $idx  
array   $param  

[ Top ]

method setErrMsg [line 359]

void setErrMsg( int $status, $param)



Tags:

access:  public


Parameters:

int   $status   ステータス
array   $param   array(フィールドラベル, ファイル名, ファイルパス)

[ Top ]

method setResult [line 307]

void setResult( $fieldlabel, $orig_filename, $filename, $filepath)



Tags:

access:  protected


Parameters:

   $fieldlabel  
   $orig_filename  
   $filename  
   $filepath  

[ Top ]

method setUploadDir [line 136]

void setUploadDir( $upload_dir)



Tags:

access:  public


Parameters:

   $upload_dir  

[ Top ]

method subDir [line 144]

void subDir( $dirname)



Tags:

access:  public


Parameters:

   $dirname  

[ Top ]


Class Constants

ERR_FAILURE =  999

[line 129]


[ Top ]

ERR_FILE_SIZE =   11

[line 124]


[ Top ]

ERR_FILE_TYPE =   12

[line 125]


[ Top ]

ERR_FORM_SIZE =  102

[line 128]


[ Top ]

ERR_INI_SIZE =  101

[line 127]


[ Top ]

ERR_MOVE =   13

[line 126]


[ Top ]

NO_FILE =    2

[line 123]


[ Top ]

SUCCESS =    1

[line 122]

phpアップロード:エラーメッセージの説明



Tags:


[ Top ]



Documentation generated on Sat, 21 May 2011 18:34:10 +0900 by phpDocumentor 1.4.1