Build a picture store path $new _avatar_path = ' avatar_origin/'. $pic _id. JPG ';
Writes the binary data from the post directly to the picture file. $len = File_put_contents (sd_root.) /'. $new _avatar_path,file_get_contents ("Php://input"));
The original picture is bigger, compress. The effect is still very obvious, using 80% compression rate of the naked eye basically no difference $avtar _img = Imagecreatefromjpeg (sd_root.) /'. $new _avatar_path); Imagejpeg ($avtar _img,sd_root. /'. $new _avatar_path,80); Nix system can use chmod ($filename, $permissions) when necessary;
Log_result (' picture size: '. $len)
The output of the newly saved picture location, the test note to change the domain name path, the following statustext is a success message. Status 1 is a successful upload, otherwise failed. $d = new Pic_data (); $d->data->photoid = $pic _id; $d->data->urls[0] = ' http://jzread.com/avatar_test/'. $new _avatar_path; $d->data->urls[0] = '/avatar_test/'. $new _avatar_path; $d->status = 1; $d->statustext = ' upload success! '
$msg = Json_encode ($d);
Echo $msg;
Log_result ($msg); function Log_result ($word) { @ $fp = fopen ("Log.txt", "a"); @flock ($fp, LOCK_EX); @fwrite ($FP, $word. " : Date of execution: ". Strftime ("%y%m%d%h%i%s ", Time ())." RN); @flock ($fp, Lock_un); @fclose ($FP); } Class Pic_data { Public $data; Public $status; Public $statusText; Public Function __construct () { $this->data->urls = Array (); } }
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.