public function upload() { try { $acceptedFormat = ['data:image/png;base64', 'data:image/jpeg;base64', 'data:image/gif;base64', 'data:image/bmp;base64']; $filePOST = Input::post('file'); $filenamePOST = htmlentities(Input::post('filename')); if (Authentication::getInstance()->isAuthenticated()) { $key = Input::post('key'); } $data = explode(',', $filePOST); if (!in_array($data[0], $acceptedFormat)) { throw new \Exception('Le format envoyé n\'est pas valide'); } $realFileName = $filenamePOST; $fileName = hash('sha256', uniqid()); $file = new \SplFileObject('content/' . $fileName, 'wb'); $file->fwrite($data[0] . ',' . $data[1]); $this->imageModel->addFile($fileName); if (Authentication::getInstance()->isAuthenticated()) { $this->imageModel->addUserFile(intval(Authentication::getInstance()->getUserId()), $fileName, $key, $realFileName); } $success = new AJAXAnswer(true, $fileName); $success->answer(); } catch (InputNotSetException $e) { $error = new AJAXAnswer(false); $error->setMessage('L\'image envoyée est trop lourde (taille conseillée < 2mo)'); $error->answer(); } catch (\Exception $e) { $error = new AJAXAnswer(false, $e->getMessage()); $error->answer(); } }
public function getPlanning() { try { $params = $this->getParams(); if (count($params) > 3 || count($params) < 3) { throw new MissingParamsException(); } if ($params != Cleaner::clean($params)) { throw new MissingParamsException(); } $response = new AJAXAnswer(true); $response->setMessage(Planning::getPlanning($params[0], $params[1], $params[2])); $response->answer(); } catch (MissingParamsException $e) { $error = new AJAXAnswer(false, 'Missing Parameters for this query'); $error->answer(); } }