public function upload_by_url() { $data = $this->get_data(); $url = $data['url']; $scale_width = intval($data['scale_width']); $x = intval($data['x']); $y = intval($data['y']); $w = intval($data['w']); $h = intval($data['h']); if ($scale_width < 1 || $x < 0 || $y < 0 || $w < 1 || $h < 1) { $this->response(ResponseType::PHOTO_UPLOAD_ERROR_SERVER); } $tmpfile = Core::tempname(); if (file_put_contents($tmpfile, file_get_contents($url))) { } else { $this->response(ResponseType::PHOTO_UPLOAD_ERROR_SERVER); } $thumb = new Thumb(); $uploader = $thumb->crop_by_url($tmpfile, $scale_width, $x, $y, $w, $h); $photoModel = new Models\Photo(); $updata['cid'] = 3; $updata['is_animated'] = 0; $updata['mtime'] = time(); if ($photoModel->create($uploader, $updata)) { $result['id'] = $photoModel->get_pid(); $result['md5'] = $photoModel->md5; $imgurls = $photoModel->geturi($result['id']); $result['src'] = $imgurls[0]; unlink($tmpfile); $this->response(ResponseType::PHOTO_GET_OK, '', $result); } else { $this->response(ResponseType::PHOTO_UPLOAD_ERROR_SERVER); } }