<?php
Save the image of the newspaper as the head upload.
Define (' Sd_root ', DirName (__file__). /');
@header ("expires:0");
@header ("Cache-control:private, Post-check=0, pre-check=0, max-age=0", FALSE);
@header ("Pragma:no-cache");
$pic _id = time ();
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://sns.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 ();
}
}
?>