public function addnew($data, $upload = true) { // dd($data); extract($data); $pathname = $upload == true ? getFileName('file') : 'default.txt'; $query = $this->db->prepare('INSERT INTO `surveys` (filename,pathname,sector_id) VALUES (:filename,:pathname,:sector)'); $query->bindParam(':filename', $filename, PDO::PARAM_STR); $query->bindParam(':pathname', $pathname, PDO::PARAM_STR); $query->bindParam(':sector', $sector, PDO::PARAM_STR); $query->execute(); getError($query); // dd(config('storage_path')); if (hasFile('file')) { move(config('storage_path_survey'), 'file'); } }
/** * Add new survey pdfs to storage */ public function addsurvey() { $Sectors = App('App\\Entities\\Survey')->listSectors(); if (request() == "post") { $data = $_POST; $filename = getFileName('file'); $filetype = getFileExtension($filename); $allowed = ['pdf', 'docx', 'doc', 'xlsx', 'xls']; if (hasFile('file')) { if (in_array($filetype, $allowed)) { App('App\\Entities\\Survey')->addnew($data); $notification = "Free survey database file successfully added"; } else { $notification = "Error: Only pdf,docx,doc,xlsx,xls uploads allowed!"; } } else { App('App\\Entities\\Survey')->addnew($data, false); $notification = "Free survey database file successfully added"; } redirect_to("/admin/survey", array('as' => 'notification', 'message' => $notification)); } backview('survey/add', compact('Sectors')); }