/**
  * 处理上传的临时文件
  * @param $uploaded_file php上传目录的临时文件
  * @param $name 上传的图片原始图片名
  * @return void
  * @author Dennis( yuantaotao@gmail.com )
  **/
 protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null)
 {
     $file = new stdClass();
     $file->size = $this->fix_integer_overflow(intval($size));
     $file->type = $type;
     $file->name = $name;
     if ($this->validate($uploaded_file, $file, $error, $index)) {
         $file_path = $this->get_distribute_path($uploaded_file, $file);
         $append_file = $content_range && is_file($file_path) && $file->size > $this->get_file_size($file_path);
         if ($uploaded_file && is_uploaded_file($uploaded_file)) {
             // multipart/formdata uploads (POST method uploads)
             if ($append_file) {
                 file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND);
             } else {
                 move_uploaded_file($uploaded_file, $file_path);
             }
         } else {
             // Non-multipart uploads (PUT method support)
             file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0);
         }
         $file_size = $this->get_file_size($file_path, TRUE);
         //比较文件的实际大小$file_size 和来自HTTP头的文件大小 $file->size
         if ($file_size === $file->size) {
             if ($this->is_valid_image_file($file_path)) {
                 //做额外处理,暂时没有需求,所以注释掉了
                 //$this->handle_image_file($file_path, $file);
                 // 上传文件过一次GD库 by FuXu 20140830
                 AdImage::retrial($file_path);
             } else {
                 unlink($file_path);
                 $file->error = $this->get_error_message('abort');
             }
         } else {
             $file->size = $file_size;
             if (!$content_range && $this->options['discard_aborted_uploads']) {
                 unlink($file_path);
                 $file->error = $this->get_error_message('abort');
             }
         }
         if ($file->error) {
             unset($file->url);
             unset($file->saved_name);
         }
         //$this->set_additional_file_properties($file);
     }
     return $file;
 }
 public function post($print_response = true, $bucket)
 {
     $res = array("status" => -1, "errmsg" => "");
     $img_data = file_get_contents("php://input");
     if (!$img_data) {
         $res["errmsg"] = "parse img data error";
         $this->_return($res);
     }
     $filemd5 = md5($img_data);
     $new_fullname = $this->get_distribute_path($filemd5);
     $bytes = file_put_contents($new_fullname, $img_data);
     if ($bytes === FALSE || (int) $bytes <= 0) {
         if (!AdImage::retrial($new_fullname)) {
             // 上传文件过一次GD库 by FuXu 20140830
             $res["errmsg"] = "save img data error";
             $this->_return($res);
         }
     }
     $res["status"] = 0;
     $res["picture"] = $bucket . "/" . $filemd5 . ".jpg";
     $this->_return($res);
 }