germanoalves
<>
Hi!
I'm trying to perform the process to rename images resulting from using the upload field using this script
// use Joomla file utils
jimport( 'joomla.filesystem.file' );
// get the original file and split it into parts
$old = ($formModel->formData['file']);
$oldParts = pathinfo($old);
// in this example we're using the id as the new filename
$sid = $formModel->formData['id'];
//create the new file (path and name)
$new = $oldParts['dirname'].'/'.$sid.'.'.$oldParts['extension'];
// update the file itself
JFile::move(JPATH_SITE.$old, JPATH_SITE.$new);
// update the data
$formModel->updateFormData('file', $new, true);
// update the db
$object = new stdClass();
// Must be a valid primary key value.
$object->id = $sid;
// new path + name
$object->file = $new;
// Update the data in the db
$result = JFactory::getDbo()->updateObject('ep_submission', $object, 'id');
I also saw this documentation https://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase
my database is called "my_bank" and the table is called, for example, "tableX" .
In this table there is a column called "photo" where it is to store the uploaded images.
In the script I already put the name of the table always returns an error saying that the table does not exist.
What would be the correct way to run this script to rename files, in my case, images?
Thanks!
I'm trying to perform the process to rename images resulting from using the upload field using this script
// use Joomla file utils
jimport( 'joomla.filesystem.file' );
// get the original file and split it into parts
$old = ($formModel->formData['file']);
$oldParts = pathinfo($old);
// in this example we're using the id as the new filename
$sid = $formModel->formData['id'];
//create the new file (path and name)
$new = $oldParts['dirname'].'/'.$sid.'.'.$oldParts['extension'];
// update the file itself
JFile::move(JPATH_SITE.$old, JPATH_SITE.$new);
// update the data
$formModel->updateFormData('file', $new, true);
// update the db
$object = new stdClass();
// Must be a valid primary key value.
$object->id = $sid;
// new path + name
$object->file = $new;
// Update the data in the db
$result = JFactory::getDbo()->updateObject('ep_submission', $object, 'id');
I also saw this documentation https://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase
my database is called "my_bank" and the table is called, for example, "tableX" .
In this table there is a column called "photo" where it is to store the uploaded images.
In the script I already put the name of the table always returns an error saying that the table does not exist.
What would be the correct way to run this script to rename files, in my case, images?
Thanks!