麻辣堂|资源主站|开发论坛|在线手册
首页 Apache Linux Java MySQL 注册帮助 
PHP项目开发组是PHP开发资源网于2007组年建成立的项目开发团队,目前核心开发成员有27人, 项目协作成员8名.下设7个开发组,主要承接大/中型网站项目开发任务。

    由于开发任务较多,人员比较紧张,现面向社会招聘全职或者兼职开发人员,不管你是在校大学生,还是全职开发人员,以及SOHO都可以联系本站,我们可以长期合作,并为您带来丰厚的报酬。
  您现在的位置:PHP开发资源网 > 麻辣堂 > 详细资料
待解决
分享一个多文件上传的,修改自老外的class
悬赏分:20 - 2007年08月22日

up.php [php]<?php $files =array ('file1', 'file2','file3','file4','file5');//文件个数 require ("UploadFiles.class.php"); if ( isset ( $_POST['ok'] ) ) { $Upload = new Upload(); $Upload -> Files = $files; $Upload -> Dir = './uploads'; $Upload -> UnicName = 1; //是否重命名1 为是,0为否 $Upload -> AutoChmod = 1; $Upload -> Chmod =0666; $Upload -> CheckFile = 2; $Upload -> FilesExt = array ( 'gif', 'jpg' ,'png' ,'zip');//支持的格式 $Upload -> MaxFileSize = 1024*1024; $Upload -> DoUpload(); print_r ($Upload -> UploadedFiles); } $head =<< EOT; foreach ($files as $values){ $body .=" "; } $foot =<<
文件
FOT; echo $head.$body.$foot; ?> back[/php] UploadFiles.class.php [php]<?php /* +--------------------------------------------- | UploadFiles.class.php | ========================================== | by tRiNEX | 2005 (c) | ========================================== | Web: http://www.trinex.ru | Email: trinex@yandex.ru +--------------------------------------------- | | > Upload Files with web-interface. | > Date started: 18 Jule, 2005 | > Filename: UploadFiles.class.php | > Version: 1.1 | +--------------------------------------------- */ Class Upload { /** * @var array of string */ var $Files = array ( 'filename' ); /** * @var string */ var $Dir = './uploads'; /** * @var integer */ var $UnicName = 1; /** * @var integer */ var $AutoChmod = 1; /** * @var integer */ var $Chmod = 0644; /** * @var integer */ var $CheckFile = 2; /** * @var array of string */ var $FilesExt = array ( 'gif', 'jpg', 'bmp' ); /** * @var integer */ var $MaxFileSize = 1024000000; /** * @var array of string */ var $UploadedFiles; /** out time **/ var $time =120; /** * @var array of string */ var $ErrorsDesc = array ( 0 => 'Value: 0; There is no error, the file uploaded with success.', 1 => 'Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.', 2 => 'Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', 3 => 'Value: 3; The uploaded file was only partially uploaded.', 4 => 'Value: 4; No file was uploaded.', 5 => 'Value: 5; No file to upload', 6 => 'Value: 6; Missing a temporary folder.', 7 => 'Value: 7; Error of file extension.', 8 => 'Value: 8; Error of file size', 9 => 'Value: 9; Error of existing file. File already exist.' ); /** * DoUpload file */ function DoUpload () { @ set_time_limit ( $this->$time ); foreach ( $this -> Files as $value ) { $flag = false; $filename = basename ( $_FILES[$value]['name'] ); $file = $this -> _split_filename ( $filename ); $ext = $file['ext']; $body = $file['body']; if ( ! in_array ( $ext, $this -> FilesExt ) ) { $this -> UploadedFiles[$value]['ErrorMsg'] = $this -> ErrorsDesc[7]; $flag = true; } if ( $_FILES[$value]['name'] == '' ) { $this -> UploadedFiles[$value]['ErrorMsg'] = $this -> ErrorsDesc[5]; $flag = true; } if ( $_FILES[$value]['size'] > $this -> MaxFileSize ) { $this -> UploadedFiles[$value]['ErrorMsg'] = $this -> ErrorsDesc[8]; $flag = true; } $newname = ( $this -> UnicName == 1) ? date("YmdGis").'_'.mt_rand(100, 999).'.'.$ext : $filename; $file = $this -> _split_filename ( $newname ); $body = $file['body']; $ext = $file['ext']; if ( is_file ( $this->Dir."/".$newname ) ) { if ( $this -> CheckFile == 1 ) { $flag = true; $this -> UploadedFiles[$value]['ErrorMsg'] = $this -> ErrorsDesc[9]; } elseif ( $this -> CheckFile == 2 ) { $i = 0; while ( is_file ( $this->Dir."/".$newname ) ) { $i++; $newname = md5(time()).$body.'_'.$i.'.'.$ext; } } } if ( ! $flag ) { if ( move_uploaded_file( $_FILES[$value]['tmp_name'], $this -> Dir."/".$newname ) ) { echo $this->changename; $this -> UploadedFiles[$value]['Status'] = 1; $this -> UploadedFiles[$value]['NewName'] = $newname; $this -> UploadedFiles[$value]['Size'] = $_FILES[$value]['size']; ($this -> AutoChmod == 1 ) ? @chmod ($this -> Dir."/".$newname, $this -> Chmod ) : '' ; } else { $this -> UploadedFiles[$value]['ErrorMsg'] = $this -> ErrorsDesc[$_FILES[$value]['error']]; } } } /** * image.gif -> ext = gif; body = image; * */} function _split_filename ( $file ) { $file = explode ( '.', $file); $ext = $file[ ( count ( $file ) - 1 ) ]; unset ($file[ ( count ( $file ) - 1 ) ] ); $name = implode ( '.', $file); $ret['ext'] = $ext; $ret['body'] = $name; return $ret; } } ?> [/php]

file.zip

提问者:chinahtml   08-22 08:08
答复
路过。。。顺便帮顶:)
回答者:玉米づ冰冻可乐 - 瓦岗村民 8-22 09:10
我也来回答:
不管你有没有帮助我们,瓦岗寨8万村民将感谢你。。。。。

为防止灌水,您需要计算一道数学题: 答案:
62 + 66 = ? 请将计算结果填在上面

 
[]
©2007 PhpRes.COM