Skip to content

Instantly share code, notes, and snippets.

@ackintosh
Created April 30, 2013 11:52
Show Gist options
  • Save ackintosh/5488231 to your computer and use it in GitHub Desktop.
Save ackintosh/5488231 to your computer and use it in GitHub Desktop.
File upload in FuelPHP
<!-- app/views/files/select.php -->
<p>Select</p>
<?php if (isset($html_error)): ?>
<?= $html_error; ?>
<?php endif; ?>
<?= Form::open(array('action' => 'files/upload', 'enctype' => 'multipart/form-data')); ?>
<div>
<?= Form::label('ファイル', 'uploadfile'); ?>
</div>
<div>
<?= Form::file('uploadfile'); ?>
</div>
<div>
<?= Form::submit('submit', '送信'); ?>
</div>
<?= Form::close(); ?>
<?php
/* app/classes/controller/files.php */
class Controller_Files extends Controller_Template
{
public function action_select()
{
$this->template->title = 'Files &raquo; Select';
$this->template->content = View::forge('files/select');
}
public function action_upload()
{
Upload::process(array('path' => Config::get('upload.path')));
if (Upload::is_valid())
{
Upload::save();
}
else
{
$this->template->content = View::forge('files/select');
$html_error = '';
foreach (Upload::get_errors() as $error) $html_error .= $error['errors'][0]['message'] . '<br />';
$this->template->content->set_safe('html_error', $html_error);
return;
}
$this->template->title = 'Files &raquo; Uploaded';
$this->template->content = View::forge('files/upload');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment