private
function
upFile()
{
$file
=
$this
->file =
$_FILES
[
$this
->fileField];
if
(!
$file
) {
$this
->stateInfo =
$this
->getStateInfo(
"ERROR_FILE_NOT_FOUND"
);
return
;
}
if
(
$this
->file[
'error'
]) {
$this
->stateInfo =
$this
->getStateInfo(
$file
[
'error'
]);
return
;
}
else
if
(!
file_exists
(
$file
[
'tmp_name'
])) {
$this
->stateInfo =
$this
->getStateInfo(
"ERROR_TMP_FILE_NOT_FOUND"
);
return
;
}
else
if
(!
is_uploaded_file
(
$file
[
'tmp_name'
])) {
$this
->stateInfo =
$this
->getStateInfo(
"ERROR_TMPFILE"
);
return
;
}
$this
->oriName =
$file
[
'name'
];
$this
->
fileSize
=
$file
[
'size'
];
$this
->
fileType
=
$this
->getFileExt();
$this
->fullName =
$this
->getFullName();
$this
->filePath =
$this
->getFilePath();
$this
->fileName =
$this
->getFileName();
$dirname
= dirname(
$this
->filePath);
if
(!
$this
->checkSize()) {
$this
->stateInfo =
$this
->getStateInfo(
"ERROR_SIZE_EXCEED"
);
return
;
}
if
(!
$this
->checkType()) {
$this
->stateInfo =
$this
->getStateInfo(
"ERROR_TYPE_NOT_ALLOWED"
);
return
;
}
if
(!
file_exists
(
$dirname
) && !
mkdir
(
$dirname
, 0777, true)) {
$this
->stateInfo =
$this
->getStateInfo(
"ERROR_CREATE_DIR"
);
return
;
}
else
if
(!
is_writeable
(
$dirname
)) {
$this
->stateInfo =
$this
->getStateInfo(
"ERROR_DIR_NOT_WRITEABLE"
);
return
;
}
if
(!(move_uploaded_file(
$file
[
"tmp_name"
],
$this
->filePath) &&
file_exists
(
$this
->filePath))) {
$this
->stateInfo =
$this
->getStateInfo(
"ERROR_FILE_MOVE"
);
}
else
{
$this
->stateInfo =
$this
->stateMap[0];
}
$imgPath
=
'@'
.
$dirname
.
'/'
.
$this
->fileName;
$data
= [
'myFile'
=>
$imgPath
,
'imgType'
=>4
];
$serverUrl
=
'http://img.com/api/image.action'
; //请求地址
$ch
= curl_init();
curl_setopt(
$ch
, CURLOPT_URL,
$serverUrl
);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$ch
, CURLOPT_POST, true);
curl_setopt(
$ch
, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt(
$ch
, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt(
$ch
, CURLOPT_POSTFIELDS,
$data
);
curl_setopt(
$ch
, CURLOPT_HTTPHEADER,
array
());
$result
= curl_exec(
$ch
);
curl_close(
$ch
);
$result
= json_decode(
$result
,true);
$this
->fullName =
$result
[
'imgUrlNormal'
];
}