Exemple #1
0
 /**
  * Delete an entire folder
  *
  * @return boolean
  */
 public function deleteFolder()
 {
     try {
         DB::beginTransaction();
         // Get all the files in this folder
         // and physical deleting files
         $files = $this->files;
         if (!empty($files)) {
             foreach ($files as $file) {
                 Utilities::deleteFile($file->name);
             }
             // Delete all record of files in this folder
             FmFile::where('folder_id', $this->id)->delete();
         }
         // Delete this folder
         $this->delete();
         DB::commit();
         return true;
     } catch (Exception $e) {
         DB::rollback();
         return false;
     }
 }
 /**
  * Download file
  *
  * @param int $id
  *
  * @return Response
  */
 public function downloadFile($id)
 {
     $file = FmFile::where('status', Constants::$COMMON_STATUSES['public'])->find($id);
     if (empty($file)) {
         App::abort('404');
     }
     $filePath = Utilities::getFileUploadPath() . $file->name;
     $content = file_get_contents($filePath);
     $contentLength = fileSize($filePath);
     $headers = array('Content-Length' => $contentLength, 'Content-disposition' => 'attachment; filename=' . $file->original_name);
     $finfo = new \finfo(FILEINFO_MIME_TYPE);
     $contentType = $finfo->buffer($content);
     if ($contentType == 'audio/mpeg') {
         $headers['Content-Type'] = 'application/octet-stream';
     }
     $response = Response::make($content);
     foreach ($headers as $headerName => $headerValue) {
         $response->header($headerName, $headerValue);
     }
     return $response;
 }