本文整理汇总了PHP中c2cTools::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP c2cTools::getMimeType方法的具体用法?PHP c2cTools::getMimeType怎么用?PHP c2cTools::getMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c2cTools
的用法示例。
在下文中一共展示了c2cTools::getMimeType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute(&$value, &$error)
{
// file upload check
foreach ($value['error'] as $error_code) {
if ($error_code) {
$error = $this->getParameter('upload_error');
return false;
}
}
$validation = sfConfig::get('app_images_validation');
// weight check
foreach ($value['size'] as $file_size) {
if ($file_size > $validation['weight']) {
$error = $this->getParameter('weight_error');
return false;
}
}
// type check
// FIXME with symfony 1.0, the type is the one given by the browser
// we prefer to use or own mime type checker (this is what is done in further
// versions of symfony, using system file check)
foreach ($value['tmp_name'] as $file) {
$file_type = c2cTools::getMimeType($file);
if (!in_array($file_type, $validation['mime_types'])) {
$error = $this->getParameter('type_error');
return false;
}
}
foreach ($value['tmp_name'] as $k => $filename) {
if ($value['type'][$k] != 'image/svg+xml') {
list($width, $height) = getimagesize($filename);
} else {
// are there any script?
if (SVG::hasScript($filename)) {
$error = $this->getParameter('svg_script_error');
return false;
}
// dimensions
$dimensions = SVG::getSize($filename);
if ($dimensions === false) {
$error = $this->getParameter('svg_error');
return false;
} else {
list($width, $height) = $dimensions;
}
}
// height/width check
if ($width > $validation['max_size']['width'] || $height > $validation['max_size']['height']) {
$error = $this->getParameter('max_dim_error');
return false;
}
if ($width < $validation['min_size']['width'] || $height < $validation['min_size']['height']) {
$error = $this->getParameter('min_dim_error');
return false;
}
}
return true;
}
示例2: execute
public function execute(&$value, &$error)
{
$allowed_mime_types = $this->getParameterHolder()->get('allowed');
$allowed_mime_types = is_array($allowed_mime_types) ? $allowed_mime_types : array($allowed_mime_types);
// FIXME with symfony 1.0, the type is the one given by the browser
// we prefer to use or own mime type checker (this is what is done in further
// versions of symfony, using system file check)
$mime_type = c2cTools::getMimeType($value['tmp_name']);
if (!in_array($mime_type, $allowed_mime_types)) {
$error = $this->getParameter('type_error');
return false;
}
return true;
}
示例3: execute
public function execute(&$value, &$error)
{
// whether the image was sent via plupload or not
$plupload = (bool) (!$this->getContext()->getRequest()->getParameter('noplupload', false));
// file upload check
if ($value['error']) {
// if plupload was used, most probably the resized image
// was too big, so provide custom error message
if ($plupload) {
$error = $this->getParameter('upload_resize_error');
} else {
$error = $this->getParameter('upload_error');
}
return false;
}
$validation = sfConfig::get('app_images_validation');
if ($value['size'] > $validation['weight']) {
// same as above (in this case, max_file_size from php.ini is bigger than $validation['weight'])
if ($plupload) {
$error = $this->getParameter('weight_resize_error');
} else {
$error = $this->getParameter('weight_error');
}
return false;
}
// type check
// with symfony 1.0, the type is the one given by the browser
// we prefer to use or own mime type checker (this is what is done in further
// versions of symfony, using system file check)
$mime_type = c2cTools::getMimeType($value['tmp_name']);
if (!in_array($mime_type, $validation['mime_types'])) {
$error = $this->getParameter('type_error');
return false;
}
if ($mime_type != 'image/svg+xml') {
list($width, $height) = getimagesize($value['tmp_name']);
} else {
// are there any script?
if (SVG::hasScript($value['tmp_name'])) {
$error = $this->getParameter('svg_script_error');
return false;
}
// dimensions
$dimensions = SVG::getSize($value['tmp_name']);
if ($dimensions === false) {
$error = $this->getParameter('svg_error');
return false;
} else {
list($width, $height) = $dimensions;
}
}
// height/width check (max width not checked for SVG, it is automatically resized)
if ($mime_type != 'image/svg+xml' && ($width > $validation['max_size']['width'] || $height > $validation['max_size']['height'])) {
$error = $this->getParameter('max_dim_error');
return false;
}
if ($width < $validation['min_size']['width'] || $height < $validation['min_size']['height']) {
$error = $this->getParameter('min_dim_error');
return false;
}
return true;
}
示例4: validate_image
/** This function is used to validate an uploaded image.
* It is quite similar to myImageValidator, except
* that we cannot validate images one by one (when several ones
* are uploaded at the same time). Thus, we have some custom
* validation mechanism here
*/
public static function validate_image(&$value, &$error, $i)
{
// file upload check
if ($value['error'][$i]) {
$error = 'file failed to upload';
return false;
}
$validation = sfConfig::get('app_images_validation');
if ($value['size'][$i] > $validation['weight']) {
$error = 'file is too big';
return false;
}
// type check
// FIXME with symfony 1.0, the type is the one given by the browser
// we prefer to use or own mime type checker (this is what is done in further
// versions of symfony, using system file check)
$mime_type = c2cTools::getMimeType($value['tmp_name'][$i]);
if (!in_array($mime_type, $validation['mime_types'])) {
$error = 'file has incorrect type';
return false;
}
if ($mime_type != 'image/svg+xml') {
list($width, $height) = getimagesize($value['tmp_name'][$i]);
} else {
// are there any script?
if (SVG::hasScript($value['tmp_name'][$i])) {
$error = 'file cannot contain scripts';
return false;
}
// dimensions
$dimensions = SVG::getSize($value['tmp_name'][$i]);
if ($dimensions === false) {
$error = 'file is malformed SVG';
return false;
} else {
list($width, $height) = $dimensions;
}
}
// height/width check
if ($width > $validation['max_size']['width'] || $height > $validation['max_size']['height']) {
$error = 'file is too large';
return false;
}
if ($width < $validation['min_size']['width'] || $height < $validation['min_size']['height']) {
$error = 'min_dim_error';
return false;
}
return true;
}