Php saves flash online photos and sends photos-PHP source code

Source: Internet
Author: User
Tags flock
Php save flash online photos sent photos

Script ec (2); script

// Save the image uploaded by the image header.

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

// Generate an image storage path
$ New_avatar_path = 'Avatar _ origin/'.w.pic_id.'.jpg ';

// Directly write the binary data from POST to the image file.
$ Len = file_put_contents (SD_ROOT. './'. $ new_avatar_path, file_get_contents ("php: // input "));

// The original image is relatively large and compressed. The effect is quite obvious. there is basically no difference in the visual display with a compression ratio of 80%.
$ Avtar_img = imagecreatefromjpeg (SD_ROOT. './'. $ new_avatar_path );
Imagejpeg ($ avtar_img, SD_ROOT. './'. $ new_avatar_path, 80 );
// You can use chmod ($ filename, $ permissions) when necessary in the nix system );

Log_result ('image size: '. $ len );


// Output the location of the newly saved image. During the test, change the domain name path. The statusText message is a success prompt.
// If status is set to 1, the upload is successful. Otherwise, the upload fails.
$ D = new pic_data ();
$ D-> data-> photoId = $ pic_id;
// $ D-> data-> urls [0] = 'HTTP: // sns.com/avatar_test/'.w.new_avatar_path;
$ D-> data-> urls [0] = '/avatar_test/'. $ new_avatar_path;
$ D-> status = 1;
$ D-> statusText = 'upload successful! ';

$ Msg = json_encode ($ d );

Echo $ msg;

Log_result ($ msg );
Function log_result ($ word ){
@ $ Fp = fopen ("log.txt", "");
@ Flock ($ fp, LOCK_EX );
@ Fwrite ($ fp, $ word. ": execution date :". 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 ();
}
}

?>

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.