コード例 #1
0
 /**
  * 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;
 }