hi, I'm trying to upload a pdf file, but only some html code goes to my table and no document is uploading.
here is my controller(it is a copy on the "post example"):
public function action_create($id = null)
{
/**/
// Custom configuration for this upload
$config = array(
//'path' => DOCROOT.DS.'files',
'path' => DOCROOT.'assets'.'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 contains an array of all error occurred
// each array element is an an array containing 'error' and 'message'
}
/**/
if (Input::method() == 'POST')
{
$val = Model_Newsrh::validate('create');
if ($val->run())
{
$newsrh = Model_Newsrh::forge(array(
'titre' => Input::post('titre'),
'contenu' => Form::file('contenu'),
));
if ($newsrh and $newsrh->save())
{
Session::set_flash('success', 'Added post #'.$post->id.'.');
Response::redirect('admin/newsrhs');
}
else
{
Session::set_flash('error', 'Could not save news rh.');
}
}
else
{
Session::set_flash('error', $val->show_errors());
}
}
$this->template->title = "News RH";
$this->template->content = View::forge('admin/newsrhs/create');
}
here is my view:
<?php echo Form::open(array('enctype' => 'multipart/form-data','class' => 'form-stacked')); ?>
<fieldset>
<div class="clearfix">
<?php echo Form::label('titre', 'titre'); ?>
<div class="input">
<?php echo Form::input('titre', Input::post('titre', isset($newsrh) ? $newsrh->titre : ''), array('class' => 'span6')); ?>
</div>
</div>
<div class="clearfix">
<?php echo Form::label('contenu', 'contenu'); ?>
can someone see where is my mistake? is my "Form::input" correct?
another question, do I need to create the table "Uploads" or fuel do it?
thanks for your help
<div class="input">
<?php echo Form::file(isset($newsrh) ? $newsrh->contenu : '', array('class' => 'span6')); ?>
</div>
</div>
<div class="clearfix">
<?php echo isset($created_at) ? Form::label('date', 'date') : ''; ?>
<div class="input">
<?php echo isset($created_at) ? Date::forge( $newsrh->created_at )->format("%d/%m/%Y") : ''; ?>
</div>
</div>
<div class="actions">
<?php echo Form::submit('submit', 'Save', array('class' => 'btn primary')); ?>
</div>
</fieldset>
<?php echo Form::close(); ?>
and the code who is one the table instead of the document name "<input name="contenu" type="file" value="" id="form_contenu" />",
I Know That i've checked my html code but i don t Know how to fill this parameter i CAN't find the good doc about it
I tried <?php echo Form::file('fichier', isset($newsrh) ? $newsrh->contenu : '', array('class' => 'span6')); ?> but it cause an error, can you help me to write it in the good way, thank you
i have changed my code so my so I have a proper html code (still would like the doc about the 'Form::file() if you have one)
my controller looks like
/**/
// Custom configuration for this upload
$config = array(
//'path' => DOCROOT.DS.'files',
'path' => DOCROOT.'assets'.'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_Newsrh::add(Upload::get_files());
}
// and process any errors
foreach (Upload::get_errors() as $file)
{
// $file is an array with all file information,
// $file contains an array of all error occurred
// each array element is an an array containing 'error' and 'message'
}
/**/
and it gives me back the following error "Fuel\Core\FuelException [ Error ]: Invalid method call. Method add does not exist.", is anyone know why? thank you
I'm working on a function "add "on my model
here is my function
public static function add($factory)
{
print_r($factory);
echo $factory[0];
Model_Newsrh::forge(array('contenu' => $factory[0],));
}
it gives me the error "Fuel\Core\Database_Exception [ Error ]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'contenu' cannot be null with query: "INSERT INTO `newsrhs` (`titre`, `contenu`, `created_at`, `updated_at`) VALUES ('tata', null, 1332251616, 1332251616)"" and I know that $factory[0] has the good value... can someone explain me my error in that one
thank you
ok I think I have resolved the post above.. now my question is on the folder path:
'path' => DOCROOT.DS.'assets'.'pdf',
I want my upload document to go on /public/assets/pdf for the moment it goes to /public/assetspdf/
how can I reach a sub folder ('path' => DOCROOT.DS.'assets/'.'pdf' doesn't work...)
thanks you
Have a close look at what you're trying to specify.
DOCROOT always has a terminating slash, so DS isn't needed there. And if you need 'assets/pdf', why don't you put a DS in between the two?
'path' => DOCROOT.'assets'.DS.'pdf', cause an error as well, I tried different solution, they all cause an error, that's why i sent a post... I don't understand this error, can you help me thanks
'path' => DOCROOT.'assets'.DS.'pdf', cause an error as well, I tried different solution, they all cause an error, that's why i sent a post... I don't understand this error, can you help me thanks
another question can I chosse the name of my upload file, on my folder my file are called like (0eff1a6cd184ae7e7cabfcb3fcde836c.pdf) I would prefer the fine name, do you know how to do it? or at least indicate this value on the database, so I can find this document when I need it... thank you
With all due respect, I think it is time you should start reading and trying to understand it before you grab your keyboard.
FuelPHP is not a framework for the absolute beginner, and I don't have the time to keep answering questions that you could have solved yourself by simply reading and trying to understand. If this is to difficult, then maybe FuelPHP is not for you.
This is a typical example: you specify you want to randomize the filename, then complain that the filename is randomized and you don't want that.
you are totally right , I apologize, went throughout the upload class doc again and find my error by myself. I agree fuel is a bit to advance for me but I started a project on it and I have to finish it now, moreover the only way to improve is to work on a hard work... so sorry again, I'll not bother you with "beginner staff" in the future.