代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
PHP
】
简单的php上传类
作者:
mako
/ 发布于
2012/4/7
/
635
<div><?php /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</div> <div> This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.</div> <div> You should have received a copy of the GNU General Public License along with this program. If not, see <<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>>. * */</div> <div>class FileUpload { /* * @FILE: Takes a file from a $_FILES via a $_POST and sets the UPLOAD DIR. * Tests that the submitted data is a type ARRAY * The resulting file is then uploaded to the DIR. * The returning data is a notification to the user. * * @AUTHOR:Sheldon Kemper * @EMAIL:<a href="mailto:sheldonkemper@gmail.com">sheldonkemper@gmail.com</a> * @DATE:17 January 2012 * @COPYRIGHT:COPYRIGHT 2012 Sheldon Kemper GPL V3 * * @TDO:Needs error-checking * Needs File-type checking * * Create a Multiple file Method. * Needs a test of supplied array matching $_FILES variables. * * */</div> <div>const BOOLTRUE = 1;//Boolean TRUE. const BOOLFALSE = 0;//Boolean FALSE. //REMOVE const FILEUPCOMPLETE ='File uploaded SUCCESFULLY'; //REMOVE const FILEUPFAILURE ='File uploaded FAILED';</div> <div>private $dirSet;//location of file uploads. private $file;//Post input of type FILE. private $errorCode;//The error code associated with this file upload. private $fileName;//The original name of the file on the client machine. private $fileType; //The mime type of the file, if the browser provided this information. An example would be "image/gif". private $fileSize; //The size, in bytes, of the uploaded file. private $fileTempName; //The temporary filename of the file in which the uploaded file was stored on the server. private $uploadFile;//Concates the $dirset with the filename. public $message;//?</div> <div> /* * @METHOD :PUBLIC MAGIC_METHOD __CONSTRUCT. * @DESC :Initialises the file_upload process . * @RETURN:Type STRING * */ public function __construct ( /*REMOVE $dir, $value*/ $config_array ) {</div> <div>$this->action_multiple_file_upload ( $config_array ) ;</div> <div>//REMOVE19012012 $this->set_dir ( $dir ); //REMOVE19012012 $this->set_postFile ( $value ); //REMOVE19012012 $this->action_file_move ();</div> <div>} <div>/* * @METHOD :PUBLIC get_fileName. * @DESC :Gets the upload file name. * @RETURN:(string) FileName. * */ public function get_fileName () {</div> <div>return $this->fileName; } <div>/* * @METHOD :PUBLIC get_fileTempName. * @DESC :Gets the upload Temp file name. * @RETURN:(string) TempFileName. * */ public function get_fileTempName () {</div> <div>return $this->fileType; } <div>/* * @METHOD :PUBLIC get_errorCode. * @DESC :Gets the upload Error Code. * @RETURN:(int) Error code. * */ public function get_errorCode () {</div> <div>return $this->errorCode; } <div>/* * @METHOD :PUBLIC get_fileType. * @DESC :Gets the upload File Type. * @RETURN:(string) File Type. * */ public function get_fileType () {</div> <div>return $this->fileType; } <div>/* * @METHOD :PRIVATE set_dir. * @DESC :Sets the upload directory. * @RETURN: * */ private function set_dir ( $dir ) {</div> <div>$this->dirSet = $dir; } <div>/* * @METHOD :PRIVATE set_postFile. * @DESC :Sets the $_FILES . * @RETURN: * */ private function set_postFile ( $value ) {</div> if( isset( $_FILES[ $value ]) ) {</div> <div> $this->file = $_FILES[$value]; } } <div>/* * @METHOD :PRIVATE action_file_move. * @DESC :Tests if a POST file was uploaded * Moves file to location. * @RETURN:CONST(string). * * */ public function action_file_move ( ) {</div> if( $this->bool_file_upload()==1 ) {</div> <div>$this->uploadfile = $this->dirSet.'/'.$this->fileName;</div> if( move_uploaded_file( $this->fileTempName,$this->uploadfile )) {</div> <div>return self::BOOLTRUE;</div> <div>}else {</div> <div>return self::BOOLFALSE; }//End IF move_uploaded_file.</div> <div>} else {</div> <div>return self::BOOLFALSE; }//End IF bool_file_upload. }//END:METHOD action_file_move.</div> <div> /* @METHOD :Private action_multiple_file_upload * @DESC :Allows for multiple file upload to more than one DIR * * @RETURN: (string) filename * * */ private function action_multiple_file_upload ( $config_array ) {</div> <div>$this->message = array();</div> <div>foreach ( $config_array as $dir=>$value ) {</div> <div>$this->set_dir ( $dir );</div> <div>$this->set_postFile ( $value );</div> if ( $this ->action_file_move ( ) ) {</div> <div>$this->message[] =$this -> get_fileName(); }//End IF. }//End FOREACH $config_array.</div> <div>return $this->message; }//END:METHOD action_multiple_file_upload.</div> <div>/* * @METHOD :PRIVATE array_confirm. * @DESC :Tests if passed argument is type ARRAY. * @RETURN:BOOL. * */</div> <div>private function array_confirm ( $file ) {</div> if ( is_array( $file ) ) {</div> <div>return self::BOOLTRUE;</div> <div>} else {</div> <div> return self::BOOLFALSE ;</div> <div> }//End IF is_array }//End METHOD array_confirm</div> <div>/* * @METHOD :PRIVATE get_loop_array * @DESC :Tests the array for $_FILES value * adding to the variables index * @RETURN:Sets private variables to VALUE * @Param( Array,$array ) :Global $_FILE * */</div> <div>private function get_array_post_loop ( $array ) {</div> if( $this->array_confirm ( $array ) ) {</div> <div>foreach ( $array as $key=>$value ) {</div> <div>switch( $key ) {</div> <div>case 'name': $this->fileName = $value; break;</div> <div>case 'error': $this->errorCode = $value; break;</div> <div>case 'type': $this->fileType = $value; break;</div> <div>case 'size': $this->fileSize = $value; break;</div> <div>case 'tmp_name': $this->fileTempName = $value; break;</div> <div>default :</div> <div>throw New Exception('Not a File');</div> <div>} //End SWITCH } //End FOREACH }//End IF array_confirm } //END METHOD loop_array</div> <div> /* * @METHOD :PRIVATE bool_file_upload * @DESC :Gets the array of values, * tests if it is uploaded via the POST * @RETURN:BOOL. * * */</div> <div>private function bool_file_upload (){</div> <div>$this->get_array_post_loop ( $this->file );</div> if(is_uploaded_file( $this->fileTempName )) {</div> <div>return self::BOOLTRUE;</div> <div>} else {</div> <div>return self::BOOLFALSE;</div> <div>}//End IF</div> <div>}//END: METHOD bool_file_upload</div> <div></div> <div>/***************END CLASS*********************/ }
试试其它关键字
php上传类
同语言下
.
用net匹配并替换iOS标准的emoji表情符号
.
处理带Emoji表情的的字符串
.
获取微信昵称时 过滤特殊字符
.
通过判断上传文件的头字符来判断文件的类型
.
模拟百度URL加密解密算法
.
以太坊检查地址是否合法
.
实现crontab解析类
.
获取每个月的开始和结束时间
.
图片上传工具类
.
APP手机应用信息采集
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
mako
贡献的其它代码
(
1
)
.
简单的php上传类
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3