public function actionPersistentNotify() { $result = json_decode(file_get_contents("php://input")); foreach ($result->items as $item) { $key = substr($item->key, 0, strlen($item->key) - 5); $uploadFile = UploadFile::model()->findByAttributes(array('path' => $key)); if ($uploadFile) { if ($item->code == 0) { $uploadFile->convertStatus = "success"; } else { if ($item->code == 1) { $uploadFile->convertStatus = "waiting"; } else { if ($item->code == 2) { $uploadFile->convertStatus = "doing"; } else { if ($item->code == 3 || $item->code == 4) { $uploadFile->convertStatus = "error"; error_log(print_r($item, true)); } } } } $uploadFile->convertKey = "{$key}.m3u8"; // error_log(print_r($uploadFile,true)); if ($uploadFile->save()) { // error_log('s'); } else { error_log('fail in persistentNotify'); } } } }
public function getFile() { $criteria = new CDbCriteria(); $criteria->join = "left join ew_lesson l on l.mediaId=t.id"; $criteria->condition = "l.mediaType='video' and l.id=" . intval($this->id); $file = UploadFile::model()->find($criteria); return $file; }
public function actionConvert() { $files = UploadFile::model()->findAllByAttributes(array('storage' => 'cloud')); $cloud = CloudService::getInstance(); foreach ($files as $file) { if (!$file->convertKey) { echo $file->path; echo $cloud->convert($file->path); echo "\n"; } } }
public function getOldFile() { if ($this->_oldMediaType == "video" && $this->_oldMediaId) { return UploadFile::model()->findByPk($this->_oldMediaId); } }
/** * 保存一个附件 * @param unknown_type $attribute * @throws CException */ public function saveAttachment($attribute) { $file = AttachmentUploadedFile::getInstance($this->Owner, $attribute); if (!is_null($file)) { // if(!$this->Owner->isNewRecord){ //delete previous attachment // if(file_exists($this->Owner->{$attribute})){ $this->Owner->refresh(); $uploadFile = UploadFile::model()->findByPk($this->Owner->{$attribute}); if ($uploadFile) { $uploadFile->delete(); } $this->Owner->isNewRecord = false; //unlink($this->Owner->{$attribute}); // } // }else{ // $this->Owner->isNewRecord = false; // } preg_match('/\\.(.*)$/', $file->name, $matches); $this->file_extension = end($matches); //检查后缀名是否符合 if (!empty($this->items[$attribute]['exts']) && !in_array($this->file_extension, $this->items[$attribute]['exts'])) { return false; } $this->filename = $file->name; $path = $this->getParsedPath($attribute); preg_match('|^(.*[\\\\/])|', $path, $match); $folder = end($match); if (!is_dir($folder)) { mkdir($folder, 0777, true); } $file->saveAs($path, false); $file_type = filetype($path); $uploadFile = new UploadFile(); $uploadFile->userId = Yii::app()->user->id; $uploadFile->addTime = time(); $uploadFile->name = $file->name; //$uploadFile->mime = mime_content_type($path); $uploadFile->mime = CFileHelper::getMimeType($path) ? CFileHelper::getMimeType($path) : ""; $uploadFile->type = $this->file_extension; $uploadFile->size = filesize($path); $uploadFile->path = $path; $uploadFile->save(); $this->Owner->saveAttributes(array($attribute => $uploadFile->id)); } return true; }