Hawk - PHP documentation
  • Namespace
  • Class
  • Tree

Namespaces

  • Hawk
    • View
      • Plugins

Classes

  • Hawk\App
  • Hawk\ButtonInput
  • Hawk\Cache
  • Hawk\CheckboxInput
  • Hawk\ColorInput
  • Hawk\Conf
  • Hawk\Controller
  • Hawk\Crypto
  • Hawk\DatabaseSessionHandler
  • Hawk\DatetimeInput
  • Hawk\DB
  • Hawk\DBExample
  • Hawk\DeleteInput
  • Hawk\Dialogbox
  • Hawk\EmailInput
  • Hawk\ErrorHandler
  • Hawk\Event
  • Hawk\FileInput
  • Hawk\FileSystem
  • Hawk\FloatInput
  • Hawk\Form
  • Hawk\FormFieldset
  • Hawk\FormInput
  • Hawk\GenericModel
  • Hawk\GifImage
  • Hawk\HawkApi
  • Hawk\HawkUpdater
  • Hawk\HiddenInput
  • Hawk\HtmlInput
  • Hawk\HTTPRequest
  • Hawk\Icon
  • Hawk\Image
  • Hawk\IntegerInput
  • Hawk\ItemList
  • Hawk\ItemListField
  • Hawk\JpegImage
  • Hawk\Lang
  • Hawk\Language
  • Hawk\LeftSidebarTab
  • Hawk\Less
  • Hawk\Logger
  • Hawk\Mail
  • Hawk\MenuItem
  • Hawk\Model
  • Hawk\NoSidebarTab
  • Hawk\NumberInput
  • Hawk\ObjectInput
  • Hawk\Option
  • Hawk\Panel
  • Hawk\PasswordInput
  • Hawk\Permission
  • Hawk\Plugin
  • Hawk\PluginInstaller
  • Hawk\PngImage
  • Hawk\ProfileQuestion
  • Hawk\ProfileQuestionValue
  • Hawk\RadioInput
  • Hawk\Request
  • Hawk\Response
  • Hawk\RightSidebarTab
  • Hawk\Role
  • Hawk\RolePermission
  • Hawk\Route
  • Hawk\Router
  • Hawk\SelectInput
  • Hawk\Session
  • Hawk\Singleton
  • Hawk\SubmitInput
  • Hawk\Tabs
  • Hawk\TextareaInput
  • Hawk\TextInput
  • Hawk\Theme
  • Hawk\TimeInput
  • Hawk\Upload
  • Hawk\User
  • Hawk\View
  • Hawk\View\Plugins\Accordion
  • Hawk\View\Plugins\Button
  • Hawk\View\Plugins\Form
  • Hawk\View\Plugins\Icon
  • Hawk\View\Plugins\Import
  • Hawk\View\Plugins\Panel
  • Hawk\View\Plugins\Tabs
  • Hawk\View\Plugins\Text
  • Hawk\View\Plugins\Uri
  • Hawk\View\Plugins\Widget
  • Hawk\ViewPlugin
  • Hawk\Widget
  • Hawk\WysiwygInput

Traits

  • Hawk\Utils

Exceptions

  • Hawk\AppStopException
  • Hawk\DBExampleException
  • Hawk\DBException
  • Hawk\FileSystemException
  • Hawk\HawkApiException
  • Hawk\ImageException
  • Hawk\MailException
  • Hawk\UploadException
  • Hawk\ViewException
 1 <?php
 2 /**
 3  * FileInput.php
 4  *
 5  * @author  Elvyrra SAS
 6  * @license http://rem.mit-license.org/ MIT
 7  */
 8 
 9 namespace Hawk;
10 
11 /**
12  * This class describes the file inputs behavior
13  *
14  * @package Form\Input
15  */
16 class FileInput extends FormInput{
17     const TYPE = "file";
18 
19     // This type of file is independant, no data is get or set in the database
20     const INDEPENDANT = true;
21 
22     /**
23      * Defines the 'multiple' attribute of the input
24      *
25      * @var boolean
26      */
27     public     $multiple = false;
28 
29     /**
30      * Defines which extensions are allowed to be uploaded with this input
31      *
32      * @var array
33      */
34     public $extensions = array();
35 
36 
37     /**
38      * Display the file input
39      *
40      * @return string The displayed HTML
41      */
42     public function display(){
43         $this->value = '';
44 
45         return parent::display();
46     }
47 
48     /**
49      * Check the submitted value of the input
50      *
51      * @param Form $form The form the input is associated with
52      *
53      * @return boolean true if the uploaded files are correct, else false
54      */
55     public function check(&$form = null){
56         if(empty($this->errorAt)) {
57             $this->errorAt = $this->name;
58         }
59 
60         $basename = preg_replace("/^(\w+)(\[.*)?$/", "$1", $this->name);
61         $upload = Upload::getInstance($basename);
62 
63         if($this->required && !$upload) {
64             // No file were uploaded
65             $form->error($this->errorAt, Lang::get('form.required-field'));
66             return false;
67         }
68 
69         if($upload && $this->extensions) {
70             foreach($upload->getFiles() as $file){
71                 if(!in_array($file->extension, $this->extensions)) {
72                     // One of the uploaded files has no good extension
73                     $form && $form->error($this->errorAt, Lang::get('form.invalid-file-extension'));
74                     return false;
75                 }
76             }
77         }
78         return true;
79     }
80 }
81 
Hawk - PHP documentation API documentation generated by ApiGen