Hey,
I've created this simple image upload where it takes the file, modifies it based on the config i set and then moves it to the proper directory. When it processes the image i decided to randomize it's name.
After the file is moved i wan't to add a record of this to the database so i get the uploaded files with Upload::get_files() but this contains the old file information and i need the new modified information with the new image name so i can properly save a reference to the database.
If anyone could help me with this i would be very happy!
Here is what i've got in the controller:
<code>
public function action_images($id = null)
{
if (Input::method() == "POST")
{
$config = array(
'path' => DOCROOT.'uploads/images',
'randomize' => true,
'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'),
);
Upload::process($config);
if (Upload::is_valid())
{
Upload::save();
foreach (Upload::get_files() as $file)
{
$files = array(
'vehicle_id' => $id,
'path' => $config,
'file' => $file,
);
Model_Vehicle_Image::forge($files)->save();
}
Session::set_flash('success', 'File uploaded!');
}
else
{
Session::set_flash('error', 'Something went HORRIBLY wrong!');
}
foreach (Upload::get_errors() as $file_error)
{
Session::set_flash('error', $file_error);
}
Response::redirect('admin/vehicles/');
}
$this->template->set_global('id', $id, false);
$this->template->title = "Add Images";
$this->template->content = View::forge('admin/vehicles/images');
}
</code>
After save(), this information should be available in the info array, with the keys 'saved_to' and 'saved_as'.
The file info itself is unchanged so you have access to the original details as they were uploaded. You need this for example if you want to store the original filename in the database, and link it to the random filename on disk.