~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Validate/File/ExcludeMimeType.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
7
 * This source file is subject to the new BSD license that is bundled
 
8
 * with this package in the file LICENSE.txt.
 
9
 * It is also available through the world-wide-web at this URL:
 
10
 * http://framework.zend.com/license/new-bsd
 
11
 * If you did not receive a copy of the license and are unable to
 
12
 * obtain it through the world-wide-web, please send an email
 
13
 * to license@zend.com so we can send you a copy immediately.
 
14
 *
 
15
 * @category  Zend
 
16
 * @package   Zend_Validate
 
17
 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
18
 * @license   http://framework.zend.com/license/new-bsd     New BSD License
 
19
 * @version   $Id: $
 
20
 */
 
21
 
 
22
/**
 
23
 * @see Zend_Validate_File_MimeType
 
24
 */
 
25
require_once 'Zend/Validate/File/MimeType.php';
 
26
 
 
27
/**
 
28
 * Validator for the mime type of a file
 
29
 *
 
30
 * @category  Zend
 
31
 * @package   Zend_Validate
 
32
 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
33
 * @license   http://framework.zend.com/license/new-bsd     New BSD License
 
34
 */
 
35
class Zend_Validate_File_ExcludeMimeType extends Zend_Validate_File_MimeType
 
36
{
 
37
    const FALSE_TYPE   = 'fileExcludeMimeTypeFalse';
 
38
    const NOT_DETECTED = 'fileExcludeMimeTypeNotDetected';
 
39
    const NOT_READABLE = 'fileExcludeMimeTypeNotReadable';
 
40
 
 
41
    /**
 
42
     * Defined by Zend_Validate_Interface
 
43
     *
 
44
     * Returns true if the mimetype of the file does not matche the given ones. Also parts
 
45
     * of mimetypes can be checked. If you give for example "image" all image
 
46
     * mime types will not be accepted like "image/gif", "image/jpeg" and so on.
 
47
     *
 
48
     * @param  string $value Real file to check for mimetype
 
49
     * @param  array  $file  File data from Zend_File_Transfer
 
50
     * @return boolean
 
51
     */
 
52
    public function isValid($value, $file = null)
 
53
    {
 
54
        // Is file readable ?
 
55
        require_once 'Zend/Loader.php';
 
56
        if (!Zend_Loader::isReadable($value)) {
 
57
            return $this->_throw($file, self::NOT_READABLE);
 
58
        }
 
59
 
 
60
        if ($file !== null) {
 
61
            if (class_exists('finfo', false) && defined('MAGIC')) {
 
62
                $mime = new finfo(FILEINFO_MIME);
 
63
                $this->_type = $mime->file($value);
 
64
                unset($mime);
 
65
            } elseif (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
 
66
                $this->_type = mime_content_type($value);
 
67
            } else {
 
68
                $this->_type = $file['type'];
 
69
            }
 
70
        }
 
71
 
 
72
        if (empty($this->_type)) {
 
73
            return $this->_throw($file, self::NOT_DETECTED);
 
74
        }
 
75
 
 
76
        $mimetype = $this->getMimeType(true);
 
77
        if (in_array($this->_type, $mimetype)) {
 
78
            return $this->_throw($file, self::FALSE_TYPE);
 
79
        }
 
80
 
 
81
        $types = explode('/', $this->_type);
 
82
        $types = array_merge($types, explode('-', $this->_type));
 
83
        foreach($mimetype as $mime) {
 
84
            if (in_array($mime, $types)) {
 
85
                return $this->_throw($file, self::FALSE_TYPE);
 
86
            }
 
87
        }
 
88
 
 
89
        return true;
 
90
    }
 
91
}