Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get file path by file name in database - Yii
class File extends CActiveRecord
public function rules()
array('filename', 'file', 'types'=>'pdf, doc, docx, xls, xlsx, ods, odt, zip, rar, avi, mp4, flv, txt, webm', 'allowEmpty' => true),
* Get file path by file name in database
* @param boolean $validate whether is needed to check if file exists
* @return string path to file
public function getFilePath($validate = true)
$path = null;
if(!$validate || !empty($this->filename))
$uploadsPath = Yii::getPathOfAlias('application.uploads');
$filePath = $uploadsPath . DIRECTORY_SEPARATOR . $this->filename;
if(!$validate || file_exists($filePath))
$path = $filePath;
return $path;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.