<?php
function
__construct(
$file
) {
$this
->upload_status =
''
;
$this
->upload_message =
''
;
$this
->file =
$file
;
$this
->mime_map =
array
(
'.jpeg'
=>
array
(
'image/jpeg'
,
'image/pjpeg'
),
'.jpg'
=>
array
(
'image/jpeg'
,
'image/pjpeg'
),
'.png'
=>
array
(
'image/png'
,
'image/x-png'
),
'.gif'
=>
array
(
'image/gif'
) );
$this
->allow_ext_list =
array
(
'.jpeg'
,
'.jpg'
,
'.png'
,
'.gif'
);
$this
->upload_path =
'./upload/'
;
$this
->checkFileParam();
$this
->checkFileError();
$this
->checkFileType();
$this
->uploadStart(); }
private
function
checkFileParam() {
if
(
$this
->upload_status ===
'error'
)
return
;
$file
=
$this
->file;
$right_name
=
gettype
(
$file
[
'name'
]) ===
'string'
;
$right_type
=
gettype
(
$file
[
'type'
]) ===
'string'
;
$right_tmp_name
=
gettype
(
$file
[
'tmp_name'
]) ===
'string'
;
$right_error
=
gettype
(
$file
[
'error'
]) ===
'integer'
;
$right_size
=
gettype
(
$file
[
'size'
]) ===
'integer'
;
if
(!
$right_name
|| !
$right_type
|| !
$right_tmp_name
|| !
$right_error
|| !
$right_size
) {
$this
->upload_message =
'传入的文件对象参数不合法!'
;
$this
->upload_status =
'error'
; } }
$error
=
$this
->file[
'error'
];
if
(
$error
== 0)
return
;
switch
(
$error
) {
case
1:
$upload_message
=
'上传的文件超过了php.ini 中 upload_max_filesize 选项限制的值!'
;
break
;
case
2:
$upload_message
=
'上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值!'
;
break
;
case
3:
$upload_message
=
'文件只有部分被上传!'
;
break
;
case
4:
$upload_message
=
'没有文件被上传!'
;
break
;
case
6:
$upload_message
=
'找不到临时文件夹!'
;
break
;
case
7:
$upload_message
=
'文件写入失败!'
;
break
;
default
:
$upload_message
=
'未知错误!'
;
break
; }
$this
->upload_status =
'error'
;
$this
->upload_message =
$upload_message
; }
$type
=
$this
->file[
'type'
];
$name
=
$this
->file[
'name'
];
$tmp_name
=
$this
->file[
'tmp_name'
];
$allow_ext_list
=
$this
->allow_ext_list;
$mime_map
=
$this
->mime_map;
$name
=
$this
->file[
'name'
];
$tmp_name
=
$this
->file[
'tmp_name'
];
$ext_name
=
strtolower
(
strrchr
(
$name
,
'.'
));
$base_name
=
'UPLOAD_'
. md5(uniqid());
$upload_path
=
$this
->upload_path;