PHP save Flash online photo sent photos

Source: Internet
Author: User
Tags flock

<?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 ();
}
}

?>

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.