/** * Description: Download other documents * By: Dhara * @param type $id * @return type */ public function getDownload($id) { $record = \App\Modules\Blog\Models\PostUpload::find($id); $file = public_path() . '/../app/Modules/Blog/myupload' . '/' . $record->post_id . '/' . $record->media_name; //var_dump($file2);exit; $path_parts = pathinfo($file); $ext = strtolower($path_parts["extension"]); switch ($ext) { case "pdf": $headers = array("Content-type: application/pdf"); break; case "docx": $headers = array("Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document"); break; // add more headers for other content types here // add more headers for other content types here default: $headers = array("Content-type: application/octet-stream"); break; } return Response::download($file, $record->media_name, $headers); }
/** * Delete media when removed in update. */ public static function deleteMedia($mediaremoved) { $arrayofmediaid = explode(",", $mediaremoved); foreach ($arrayofmediaid as $id) { if (!empty($id)) { $dm = PostUpload::find($id); if (!is_null($dm)) { $dm->delete(); } } } return "media deleted successfully!!"; }