Example on renaming uploaded files doesn't work for me

AlexTCGPro

Member
Hello, I'm using the file upload element in a form and I wanted the files to be renamed either according to id or some other field of the form. I found the wiki and the code they put as an example apparently did this, so I copied it and pasted it following the instructions, however trying to submit anything in that form now crashes the whole site and brings up this error code:
1146
Table 'database.ep_submission' doesn't exist

I don't really know much about php to discover what is wrong but it seems to me that I should change the part of the code that says ep_submitions and put a table that does exist? But I'm confused as I found that exact part in other code before so I'm not sure.
 
Hi,
Well, as it says above the code in the Wiki: "You can adjust the values to meet your needs - this is just one possible example".
Obviously, you'll have to adjust the values (and maybe else) because it is unlikely that the table "ep_submission" exists in your database - as the error states, indeed.
 
Hahaha, I assumed I didn't had to change any of it, just renaming that table to the same table of the form should be enough to fix the issue, no? Thanks
 
Again, renaming the table is a must. If it's enough, depends on what you want or need, and I don't want to assume anything there... :p
 
Well, I edited it accordingly but now it says that the renaming failed, so I obviously did something wrong
Code:
jimport( 'joomla.filesystem.file' );
$old = ($formModel->formData['picture']);
$oldParts = pathinfo($old);
$sid = $formModel->formData['id'];
$new = $oldParts['dirname'].'/'.$sid.'.'.$oldParts['extension'];
JFile::move(JPATH_SITE.$old, JPATH_SITE.$new);
$formModel->updateFormData('picture', $new, true);
$object = new stdClass();
$object->id = $sid;
$object->picture= $new;
$result = JFactory::getDbo()->updateObject('students', $object, 'id');
I have no idea what should I change now, could you give me a hand? The element or "column" that holds the picture is named 'picture', id is just id
 
If you're attempting to follow the Wiki example with using a PHP form plugin, you'd need to provide a lot more information for someone to be able to help.

If you only want to rename the uploaded file, why don't you use "Rename Code" in the element's Options tab instead. It's not (yet) mentioned in the Wiki but there you can return a new name in an easier way, possibly also based on form data.

See the field's tooltip. If you search around here, you'll find more on it, e.g. http://fabrikar.com/forums/index.ph...eupload-archive-assign-a-id-user-number.49499
 
Yeah, I already looked around this forum but still wasn't able to solve my problem. I had seen the link you just posted, I want to rename the whole file to just the id, not just append it at the beginning of the file name, so that code won't do for me. I'm still completely lost
 
I want to rename the whole file to just the id

You could still change the entire file name, not just append, but yeah, if it has to be the row ID, the "Rename Code" option is not likely to work when adding new records since new records don't have an ID yet.
Though, as per tooltip, other form data should be available -- if you don't use AJAX. Or just obfuscate the filename? That's easily done under Options, obviously.

Anyway, if it must be the ID, a PHP form plugin is the way to go, and the quoted code example should still be a good start, and so is the Wiki on the PHP form plugin as well as other sources. However, don't expect to find the "one fits all incl your situation" code you can simply copy & paste. Decent PHP knowledge is certainly helpful, as well as knowing more about your specific case.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top