The method of uploading before the mobile end, some friends Test said that the micro-letter support is not very good, and some Andro also do not support, in fact, I have another method, but the example has not been sorted out, and contact me a lot of friends need, so the first hair out, and make a simple explanation, I will not do a demo.
This is also the picture into a base64 to send, the individual does not recommend to use JS to change the size of the picture, it is recommended to cut the zoom or PHP to do it.
This.maxwidth = Options.maxwidth | | ;
This.maxheight = Options.maxheight | | ;
This.maxsize = Options.maxsize | | 3 * 1024 * 1024;
This.input = Options.input;
This.mime = {' png ': ' image/png ', ' jpg ': ' image/jpeg ', ' jpeg ': ' image/jpeg ', ' bmp ': ' Image/bmp '};
This part is to upload the image configuration, should be able to understand, you can change
$.ajax {
URL: ' {: U (' upload ')} ',
data:{str:base64,type:this.filetype},
type: ' Post ',
dataType: ' JSON ',
success:function (i) {
alert (i.info);
}
This part is uploaded after the AJAX send Base64 code to PHP,
Base64 code with a picture of the description string, so you have to use the regular remove, and then Base64 decoding saved to the picture file. and return to the address can be
The content of upload.php
$STR = $_post[' str '];
$type = $_post[' type '];
Switch ($type) {case
' image/png ':
$ext = '. png ';
break;
Case ' image/jpeg ';
$ext = '. jpeg ';
break;
Case ' image/jpeg ':
$ext = '. jpg ';
break;
Case ' image/bmp ':
$ext = '. bmp ';
break;
Default:
$ext = '. jpg ';
}
$file _path= './uploads/'. Date (' Ymd '). /'. Time (). $ext;
if (!file_exists (dirname ($file _path))) {
mkdir (dirname ($file _path), 0777,true);
$img _content = str_replace (' data: '. $type. ') Base64, ', ', $str);
$img _content = Base64_decode ($img _content);
$result =file_put_contents ($file _path, $img _content);
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.