/**
  * Save Media info into database
  *
  * @param object Media
  * @param string File path
  *
  * @return bool True if successful
  **/
 protected function saveMedia($model, $filePath)
 {
     $file = new FileInfo($filePath);
     // Save the media link
     $model->path = $file->getFilename();
     // Get mime type of the file
     $model->mimetype = $file->getMimeType();
     // Get playtime of the file
     $playtime = $file->getPlaytime();
     $options = json_decode($model->options);
     if (!is_array($options)) {
         $options = array();
         // Create a new array
     }
     $options['duration'] = $playtime ? $playtime : '';
     $model->options = json_encode($options);
     try {
         $model->save();
     } catch (Exception $exp) {
         return false;
     }
     return true;
 }
示例#2
0
 public function getDuration($sid)
 {
     $media = Media::find($sid);
     $status = array();
     $status['data'] = '';
     if ($media == null) {
         $status['status'] = 'error';
         return $status;
     }
     $media_folder = public_path() . '/assets/medias/' . $media->category_id . '/' . $sid;
     $filepath = $media_folder . "/" . $media->path;
     if (file_exists($filepath) && $media->mimetype != 'application/pdf') {
         $file = new FileInfo($filepath);
         // Get playtime of the file
         $playtime = $file->getPlaytime();
         // Save playtime
         $options = json_decode($media->options);
         if (!is_array($options)) {
             $options = array();
             // Create a new array
         }
         $options['duration'] = $playtime ? $playtime : '';
         $status['data'] = $options['duration'];
         $media->options = json_encode($options);
         try {
             $media->save();
         } catch (Exception $exp) {
             $status['status'] = 'error';
             return $status;
         }
     }
     $status['status'] = 'success';
     return $status;
 }