public function action_create($id = null)
{
$config = array(
'path' => DOCROOT.DS.'files',
'randomize' => true,
'ext_whitelist' => array('pdf'),
);
// process the uploaded files in $_FILES
Upload::process($config);
// if there are any valid files
if (Upload::is_valid())
{
// save them according to the config
Upload::save();
// call a model method to update the database
Model_Uploads::add(Upload::get_files());
}
// and process any errors
foreach (Upload::get_errors() as $file)
{
// $file is an array with all file information,
// $file['errors'] contains an array of all error occurred
// each array element is an an array containing 'error' and 'message'
}
if (Input::method() == 'POST')
{
$val = Model_File::validate('create');
if ($val->run())
{
$file = Model_File::forge(array(
'filename' => Input::post('filename'),
));
if ($file and $file->save())
{
Session::set_flash('success', 'Added file #'.$file->id.'.');
Response::redirect('file');
}
else
{
Session::set_flash('error', 'Could not save file.');
}
}
else
{
Session::set_flash('error', $val->show_errors());
}
}
$this->template->title = "Files";
$this->template->content = View::forge('file/create');
}
<?php echo Form::open(array('class' => 'form-stacked')); ?>
<fieldset> <div class="clearfix"> <?php echo Form::label('Filename',
'filename'); ?>
<div class="input">
<?php
echo FORM::file('filename')
?>
<?php /* echo Form::input('filename',
Input::post('filename', isset($file) ? $file->filename : ''), array('class' =>
'span6')); */ ?>
</div>
</div> <div class="actions"> <?php echo Form::submit('submit',
'Save', array('class' => 'btn primary')); ?>
</div> </fieldset> <?php echo Form::close(); ?>
<?php echo Form::open(array('class' => 'form-stacked'));
echo FORM::file('filename'); ?>
A.: how do I append the enctype to the Form::open ?<?php echo Form::open(array('action' => '/upload', 'method' => 'post','enctype' => 'multipart/form-data')); ?>
<input type="file" name="userfile" id="file" />
<button type="submit">Upload</button>
<?php echo Form::close(); ?>
if (\Upload::is_valid()) {
\Upload::save();
$file = \Upload::get_files(0);
} else {
//throw error
}
Patrick Curl wrote on Friday 16th of March 2012:Um, Thanks for hijacking my Thread... but anyhow.. The upload processing code, that goes in the controller or model?
It doesn't really specify in the docs. also I have these two lines of code in my form:<?php echo Form::open(array('class' => 'form-stacked')); echo FORM::file('filename'); ?>A.: how do I append the enctype to the Form::open ?
B: is there anything else I should have with the FORM:file('filename')
Anything else that should be in ()? perhaps? I have some experience with Rails, and am really liking Fuel's 'oil' tool - cause it is very Rails-like.
marie vacelet wrote on Friday 16th of March 2012:to pixel gremlins, I didn't mean to "hijacking" your thread , just thought it is the same topic so didn't want to do another topic. sorry about that
A Huzz wrote on Friday 16th of March 2012:Something like this, Not tested. //View<?php echo Form::open(array('action' => '/upload', 'method' => 'post','enctype' => 'multipart/form-data')); ?> <input type="file" name="userfile" id="file" /> <button type="submit">Upload</button> <?php echo Form::close(); ?>
//Controllerif (\Upload::is_valid()) { \Upload::save(); $file = \Upload::get_files(0); } else { //throw error }Patrick Curl wrote on Friday 16th of March 2012:Um, Thanks for hijacking my Thread... but anyhow.. The upload processing code, that goes in the controller or model?
It doesn't really specify in the docs. also I have these two lines of code in my form:<?php echo Form::open(array('class' => 'form-stacked')); echo FORM::file('filename'); ?>A.: how do I append the enctype to the Form::open ?
B: is there anything else I should have with the FORM:file('filename')
Anything else that should be in ()? perhaps? I have some experience with Rails, and am really liking Fuel's 'oil' tool - cause it is very Rails-like.
<?php Form::open(array('action' => '/upload', 'method' => 'post','enctype' => 'multipart/form-data')); ?>
<fieldset> <div class="clearfix"> <?php echo Form::label('Filename',
'filename'); ?>
<div class="input">
<?php
echo FORM::file('filename')
?>
<?php /* echo Form::input('filename',
Input::post('filename', isset($file) ? $file->filename : ''), array('class' =>
'span6')); */ ?>
</div>
</div> <div class="actions"> <?php echo Form::submit('submit',
'Save', array('class' => 'btn primary')); ?>
</div> </fieldset> <?php echo Form::close(); ?>
public function action_create($id = null) {
$config = array(
'path' => DOCROOT.DS.'files',
'randomize' => true,
'ext_whitelist' => array('pdf'),
);
Upload::process($config);
if (Upload::is_valid()) {
$arr = Upload::get_files();
Upload::save(DOCROOT.'assets/files', array_keys($arr) );
Model_Files::add(Upload::get_files());
}
foreach (Upload::get_errors() as $file)
{
echo $file;
echo $file['errors'];
}
$this->template->title = "Files";
$this->template->content = View::forge('file/create');
}
Harro Verton wrote on Tuesday 20th of March 2012:Your form posts to "/upload", yet your action is called "create". Assuming that this action is in a controller called Controller_Upload, shouldn't you post to "/upload/create"?
It looks like you're new here. If you want to get involved, click one of these buttons!