FuelPHPでファイルアップロード


アップロードフォームのView

<?php echo Form::open(array("class"=>"form-horizontal", "enctype"=>"multipart/form-data")); ?>
  <?php echo Form::file('file'); ?>
  <?php echo Form::submit('submit', 'Upload', array('class' => 'btn btn-primary')); ?>
<?php echo Form::close(); ?>

Controller

public function action_upload($id = null)
{
    $config = array(
        'path' => 'files',
        'new_name' => $file_name,
        'ext_whitelist' => array('jpg', 'jpeg'),
    );
    Upload::process($config);

    if (Upload::is_valid())
    {
        Upload::save();
        $file = Upload::get_files(0);

        Session::set_flash('success', $file['name']." has been uploaded successfully.");
    }
    else
    {
        $error_file = Upload::get_errors(0);
        Session::set_flash('error', $error_file["errors"][0]["message"]);
    }
}
,