With the last blog, tinkering with a PHP backstage things, although not understand, but slowly, still Can. Transmission Door
Java is not studious, play php, meet Yourself.
The image compression effect is obvious, actually compressed several times.
<?PHPHeader(' content-type:text/html; charset= "utf-8");$base 64_image_content=$_post["file"];//var_dump ($ $base 64_image_content);if(Preg_match('/^ (data:\s*image\/(\w+); base64,)/i ',$base 64_image_content,$result)){ $type=$result[2]; $new _file= "upload/".Date("Ymd", time())." /"; if(!file_exists($new _file)){ /*Permissions issues, 0777 is best, others may be banned*/ mkdir($new _file, 0777); Echo"created successfully"; }Else{ Echo"create failed"; } $new _file=$new _file. time().". {$type}"; if(file_put_contents($new _file,Base64_decode(Str_replace($result[1], "",$base 64_image_content)))){ EchoSuccess; }Else{ EchoFailed; } }Else{ Echo"not match!!";}?>
form submission, Transferring pictures
<?PHPHeader(' content-type:text/html; charset= "utf-8");$upload _dir= ' uploads/';if(Strtolower($_server[' Request_method ']) ! = ' Post ') {exit_status (Array(' code ' =>1, ' msg ' = ' Error submission method '));}if(array_key_exists(' file ',$_files) &&$_files[' file '] [' error '] = = 0 ){ $pic=$_files[' file ']; if(Move_uploaded_file($pic[' Tmp_name '],$upload _dir.$pic[' name ']) {exit_status (Array(' code ' =>0, ' msg ' = ' upload succeeded ', ' url ' = =$upload _dir.$pic[' name '])); } }Echo $_files[' file '] [' error '];exit_status (Array(' code ' =>1, ' msg ' = ' = ' There have been some errors '));functionExit_status ($str){ EchoJson_encode ($str); Exit;}?>
Upload images in PHP background