/** * Descarrega el fitxer d'una aportació d'un esdeveniment * @param integer [$id] identificador de l'aportació */ public function descarregarFitxer($id) { try { $aportacio = Aportacio::find($id); } catch (ModelNotFoundException $e) { return Redirect::route('grups.meus'); } $esdeveniment = $aportacio->esdeveniment; $grup = $esdeveniment->grup; $grups = Auth::user()->grups()->lists('id_grup'); date_default_timezone_set("Europe/Madrid"); $ara = date("Y-m-d H:i:s"); $esdeveniment_actiu = $esdeveniment->data_esdeveniment > $ara; /*Comprovació de que l'estudiant estigui matriculat al grup d'aquesta assignatura i el grup estigui actiu*/ if (in_array($grup->getID(), $grups) && $grup->getActiu() && $esdeveniment_actiu) { $file = $aportacio->getFitxer(); if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit; } else { return Redirect::route('esdeveniment.missatges', array('slug' => $esdeveniment->getSlug()))->with('descarrega', 'error'); } } else { return Redirect::route('grups.meus'); } }
/** * Descarrega un fitxer associat a una aportació * @param string [$id] numero de l'aportacio on es adjunt el fitxer */ public function download($id) { try { $aportacio = Aportacio::find($id); } catch (ModelNotFoundException $e) { return Redirect::route('grups.meus'); } $assignatura = $aportacio->assignatura; $grup = $assignatura->grup; $grups = Auth::user()->grups()->lists('id_grup'); /*Comprovació de que l'estudiant estigui matriculat al grup d'aquesta assignatura i el grup estigui actiu*/ if (in_array($grup->getID(), $grups) && $grup->getActiu()) { $file = $aportacio->getFitxer(); if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit; } else { return Redirect::route('assignatura.info', array('slug' => $assignatura->getSlug()))->with('descarrega', 'error'); } } else { return Redirect::route('grups.meus'); } }