problem rename image:

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!
 
Are you trying to rename the files while uploading with fileupload element or you need to rename the files already uploaded earlier?
 
Something like this should do:

Code:
$rowid = $formModel->getElementData('yourtable___id');
$mydate = $formModel->getElementData('yourtable___date_element');
$ext = JFile::getExt($filename);

$filename = $rowid." - ".$mydate.".".$ext;
return $filename;
 
Almost perfect @juuser


The first line I don't know why it doesn't work, nor switching to other elements. Only the password line worked.

Could it be that there can only be 1 record to compose the name?

Thanks!
 
Hmm, almost the same code works fine for me.

What do you mean by "password line worked?

What do you get if you e.g. var dump the $rowid variable like:
var_dump($rowid);
exit;
 
like this @juuser ?


$rowid = $formModel->getElementData('database___id');
$mydate = $formModel->getElementData('database___date_time');
$ext = JFile::getExt($filename);

$filename = $rowid." - ".$mydate.".".$ext;
return $filename;


var_dump($rowid);
exit;



it returned null
 
No idea. Try to use some other element and see if that gets any data. Does it work with fixed values instead of element data.
 
I managed to resolve it.

It seems that fabrik doesn't take values directly from elements like IP and ID. But if it replicates in an element like calc, then it works.

Thanks for the help guys @juuser @troester !
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top