Why does the uploaded image contain a transparent channel and the image turns black? P.s. & nbsp; original image upload class address: blog. csdn. neta957651480articledetails23123167 & lt ;? Phpclass & nbsp; Images {var & nbsp; $ inputName; & nbsp why Images uploaded contain transparent channels, the image turns black?
P.s. modified image upload class original address: http://blog.csdn.net/a957651480/article/details/23124257
Class Images {
Var $ inputName; // control name
Var $ allowType = array (
'Image/GIF', 'image/jpg ', 'image/jpeg', 'image/png ', 'image/x-png', and 'image/pjpeg'
); // Upload type
Var $ allowSize = 1048576; // limit the size
Var $ saveDir = ""; // Save the Directory
Var $ FileName = ""; // file name
Var $ isRename = false; // whether to rename. the default value is true.
Var $ errID = 0; // error code. the default value is 0.
Var $ errMsg = ""; // error message
Var $ savePath = ""; // save path
Var $ ImgSize = 0; // Image size
Function _ construct ($ inputName, $ allowType = "", $ allowSize = "", $ saveDir = "", $ isRename = true ){
If (empty ($ inputName )){
$ This-> chk_err (-1); // no input control name
} Else {
$ This-> inputName = $ inputName;
}
If (! Empty ($ allowType) $ this-> allowType = $ allowType;
If (! Empty ($ allowSize) $ this-> allowSize = $ allowSize;
If (! Empty ($ saveDir) $ this-> saveDir = $ saveDir;
If (! Empty ($ isRename) $ this-> isRename = $ isRename;
}
Function is_uploaded (){
If (empty ($ _ FILES [$ this-> inputName] ['name']) {
$ This-> chk_err (4); // no file is uploaded
} Else {
If (is_uploaded_file ($ _ FILES [$ this-> inputName] ['tmp _ name']) {
Return true;
} Else {
$ This-> chk_err (-2); // the file upload is invalid.
}
}
}
Function chk_type (){
If (! In_array ($ _ FILES [$ this-> inputName] ['type'], $ this-> allowType )){
$ This-> chk_err (-3); // the uploaded file type is not allowed.
} Else {
Return true;
}
}
Function chk_size (){
If ($ _ FILES [$ this-> inputName] ['size']> $ this-> allowSize ){
$ This-> chk_err (-4); // the uploaded file is too large.
} Else {
Return true;
}
}
Function move_uploaded () {// Move the uploaded file
If (! $ This-> is_uploaded ()){
Return false;
}
If (! $ This-> chk_size ()){
Return false;
}
If (! $ This-> chk_type ()){
Return false;
}
// Rename
If ($ this-> isRename ){
$ ArrTmp = pathinfo ($ _ FILES [$ this-> inputName] ['name']);
$ Extension = strtolower ($ arrTmp ['extension']);
$ File_newname = $ this-> FileName; // rename a new file
} Else {
$ File_newname = $ _ FILES [$ this-> inputName] ['name'];
}
If (! File_exists ($ this-> saveDir) {// checks whether the saved directory exists.
Mkdir ($ this-> saveDir, 0777, true); // Create a save Directory
}
// Move the file
$ Result = move_uploaded_file ($ _ FILES [$ this-> inputName] ['tmp _ name'], $ this-> saveDir. "/". $ file_newname );
If ($ result ){
$ Path = $ this-> savePath = $ this-> saveDir. "/". $ file_newname; // path of the successfully saved file
Return $ path;
} Else {
$ This-> chk_err ($ _ FILES [$ this-> inputName] ['error']);
}
}
// Identify the error message
Function chk_err ($ errID ){
$ This-> errID = $ errID;
Switch ($ this-> errID ){
Case-4:
$ This-> errMsg = 'only images within 1 MB can be uploaded | [return] ';
Break;
Case-3:
$ This-> errMsg = 'this is not an image | [return]';
Break;
Case-2:
$ This-> errMsg = 'File upload is invalid | [return] ';
Break;
Case-1:
$ This-> errMsg = 'no control name passed in | [return] ';
Break;
Case 1:
$ This-> errMsg = 'the uploaded file exceeds the maximum value set by upload_max_filesize in php. ini | [return] ';
Break;
Case 2:
$ This-> errMsg = 'the size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form | [return] ';
Break;
Case 3:
$ This-> errMsg = 'only part of the file is uploaded | [return] ';
Break;
Case 4:
$ This-> errMsg = 'SELECT an image | [return] ';
Break;
Default:
Break;
}
Return false;
}
Function get_errMsg (){