public function getVideoFormat($source) { foreach ($this->_getVideoFormats() as $key => $tmp) { if (isset($tmp['regex'])) { if (preg_match($tmp['regex'], $source, $matches) && isset($matches[1])) { return $key; } } else { if (YFile::getExtension($source) == $key) { return $key; } } } return null; }
public function doUpload() { // get the uploaded file information $userfile = $this->_data->get('file'); if (is_array($userfile)) { // get file name $ext = YFile::getExtension($userfile['name']); $base_path = JPATH_ROOT . '/' . $this->_getUploadImagePath() . '/'; $file = $tmp = $base_path . $userfile['name']; $filename = basename($file, '.' . $ext); $i = 1; while (JFile::exists($tmp)) { $tmp = $base_path . $filename . '-' . $i++ . '.' . $ext; } $file = trim(str_replace('\\', '/', preg_replace('/^' . preg_quote(JPATH_ROOT, '/') . '/i', '', $tmp)), '/'); if (!JFile::upload($userfile['tmp_name'], $file)) { throw new YException('Unable to upload file.'); } $this->_data->set('file', $file); } }
public function clean($value) { if (!is_array($value) || !isset($value['tmp_name'])) { throw new YValidatorException($this->getMessage('invalid')); } if (!isset($value['name'])) { $value['name'] = ''; } $value['name'] = JFile::makeSafe($value['name']); if (!isset($value['error'])) { $value['error'] = UPLOAD_ERR_OK; } if (!isset($value['size'])) { $value['size'] = filesize($value['tmp_name']); } if (!isset($value['type'])) { $value['type'] = 'application/octet-stream'; } switch ($value['error']) { case UPLOAD_ERR_INI_SIZE: throw new YValidatorException($this->getMessage('max_size'), UPLOAD_ERR_INI_SIZE); case UPLOAD_ERR_FORM_SIZE: throw new YValidatorException($this->getMessage('max_size'), UPLOAD_ERR_FORM_SIZE); case UPLOAD_ERR_PARTIAL: throw new YValidatorException($this->getMessage('partial'), UPLOAD_ERR_PARTIAL); case UPLOAD_ERR_NO_FILE: throw new YValidatorException($this->getMessage('no_file'), UPLOAD_ERR_NO_FILE); case UPLOAD_ERR_NO_TMP_DIR: throw new YValidatorException($this->getMessage('no_tmp_dir'), UPLOAD_ERR_NO_TMP_DIR); case UPLOAD_ERR_CANT_WRITE: throw new YValidatorException($this->getMessage('cant_write'), UPLOAD_ERR_CANT_WRITE); case UPLOAD_ERR_EXTENSION: throw new YValidatorException($this->getMessage('err_extension'), UPLOAD_ERR_EXTENSION); } // check mime type if ($this->hasOption('mime_types')) { $mime_types = $this->getOption('mime_types') ? $this->getOption('mime_types') : array(); if (!in_array($value['type'], array_map('strtolower', $mime_types))) { throw new YValidatorException($this->getMessage('mime_types')); } } // check mime type group if ($this->hasOption('mime_type_group')) { if (!in_array($value['type'], $this->_getGroupMimeTypes($this->getOption('mime_type_group')))) { throw new YValidatorException($this->getMessage('mime_type_group')); } } // check file size if ($this->hasOption('max_size') && $this->getOption('max_size') < (int) $value['size']) { throw new YValidatorException(sprintf($this->getMessage('max_size'), $this->getOption('max_size') / 1024)); } // check extension if ($this->hasOption('extension') && !in_array(YFile::getExtension($value['name']), $this->getOption('extension'))) { throw new YValidatorException($this->getMessage('extension')); } return $value; }