Changeset 3293 for trunk/application

Show
Ignore:
Timestamp:
08/07/2008 12:51:06 PM (4 months ago)
Author:
OscarB
Message:

Fixes #753 thanks msaraujo

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/application/controllers/examples.php

    r3080 r3293  
    114114 
    115115        /** 
    116          * Demonstrates how to use the form helper with the Validation library. 
     116         * Demonstrates how to use the form helper with the Validation libraryfor file uploads . 
    117117         */ 
    118118        function form() 
    119119        { 
    120                 $validation = new Validation; 
    121  
    122                 echo form::open('', array('enctype' => 'multipart/form-data')); 
    123  
     120                // Anything submitted? 
     121                if ($_POST) 
     122                { 
     123                        // Merge the globals into our validation object. 
     124                        $post = Validation::factory(array_merge($_POST, $_FILES)); 
     125 
     126                        // Ensure upload helper is correctly configured, config/upload.php contains default entries. 
     127                        // Uploads can be required or optional, but should be valid 
     128                        $post->add_rules('imageup1', 'upload::required', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]'); 
     129                        $post->add_rules('imageup2', 'upload::required', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]'); 
     130 
     131                        // Alternative syntax for multiple file upload validation rules 
     132                        //$post->add_rules('imageup.*', 'upload::required', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[1M]'); 
     133 
     134                        if ($post->validate() ) 
     135                        { 
     136                                // It worked! 
     137                                // Move (and rename) the files from php upload folder to configured application folder 
     138                                upload::save('imageup1'); 
     139                                upload::save('imageup2'); 
     140                                echo 'Validation successfull, check your upload folder!'; 
     141                        } 
     142                        else 
     143                        { 
     144                                // You got validation errors 
     145                                echo '<p>validation errors: '.var_export($post->errors(), TRUE).'</p>'; 
     146                                echo Kohana::debug($post); 
     147                        } 
     148                } 
     149 
     150                // Display the form 
     151                echo form::open('examples/form', array('enctype' => 'multipart/form-data')); 
    124152                echo form::label('imageup', 'Image Uploads').':<br/>'; 
    125                 echo form::upload('imageup[]').'<br/>'; 
    126                 echo form::upload('imageup[]').'<br/>'; 
    127                 echo form::upload('imageup[]').'<br/>'; 
     153                // Use discrete upload fields 
     154                // Alternative syntax for multiple file uploads 
     155                // echo form::upload('imageup[]').'<br/>'; 
     156 
     157                echo form::upload('imageup1').'<br/>'; 
     158                echo form::upload('imageup2').'<br/>'; 
    128159                echo form::submit('upload', 'Upload!'); 
    129  
    130160                echo form::close(); 
    131161 
    132                 if ( ! empty($_POST)) 
    133                 { 
    134                         $validation->set_rules('imageup', 'required|upload[gif,png,jpg,500K]', 'Image Upload'); 
    135                         echo '<p>validation result: '.var_export($validation->run(), TRUE).'</p>'; 
    136                 } 
    137  
    138                 echo Kohana::debug($validation); 
    139                 echo Kohana::lang('core.stats_footer'); 
    140162        } 
    141163 
     
    249271        { 
    250272                $db = new Database; 
    251                  
     273 
    252274                $table = 'pages'; 
    253275                echo 'Does the '.$table.' table exist? ';