public function dataurlUploadQuery(Request $request) { $dataurl = $request->post('DataURL'); $part = parse_dataurl($dataurl); $ext = Mimes::getInstance()->ext_by_mime($part['mine']); $data = $part['data']; $file_path = tempnam(sys_get_temp_dir(), ''); $fp = fopen($file_path, 'wb+'); fwrite($fp, $data); fclose($fp); unset($dataurl, $data, $part); $attachment = $this->model->savefile($this->user['id'], $file_path, 'datauri_' . $this->user['id'] . '_' . date('Ymdhis') . '.' . $ext); return $this->success('', $url, array('id' => $attachment->getKey(), 'url' => $attachment->url())); }
private function uploadToWechat(API $api, Attachment $attachment, $type) { return $api->uploadMedia($attachment->create_symlink(NULL, NULL), $type, Mimes::getInstance()->mime_by_ext($attachment->ext)); }
protected function output(array $data, $filename = NULL, $abort = FALSE) { $request = app('request'); $charset = app('config')['app']['charset']; $of = strtolower($request->input('of')); $jsonp = isset($_GET['jsonp']) ? $_GET['jsonp'] : null; empty($jsonp) && ($jsonp = isset($_GET['callback']) ? $_GET['callback'] : null); if (!in_array($of, ['js', 'json', 'jsonp', 'xml', 'txt', 'text', 'csv', 'xls', 'xlsx', 'yaml', 'html', 'pdf'])) { if ($request->ajax()) { //自动切换ajax状态下of为json $of = empty($jsonp) ? 'json' : 'jsonp'; } else { $of = 'html'; } } $response = null; if (in_array($of, ['csv', 'xls', 'xlsx', 'pdf'])) { $filename = Output::$of($data['data']); $response = response()->download($filename, date('YmdHis') . '.' . $of, ['Content-Type' => Mimes::getInstance()->mime_by_ext($of)])->deleteFileAfterSend(TRUE); } else { $content = $of != 'html' ? Output::$of($data, $jsonp) : $this->view('tips', ['_data' => $data]); $response = response($content)->header('Content-Type', Mimes::getInstance()->mime_by_ext($of) . '; charset=' . $charset); } if ($abort) { throw new HttpResponseException($response); } return $response; }