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