File Upload - Rename

Zeon 06 Aug, 2009
Hi,
I'm working on a form where members are signing up. one of the fields is for them to upload their company logos. What I want to be able to do is insert their comapny name (its a field in chronoforms called "trading_as") at the very start of the filename.

What would I need to enter in the "FileName Format" field to do this?

Thanks
GreyHead 06 Aug, 2009
Hi Zeon,

I'm not 100% certain. Try
$filename = JRequest::getString('trading_as', 'no_name_entered', 'post');

Bob
Zeon 06 Aug, 2009
Works great thanks!

Just a tip to anyone reading this - the form fields are case sensitive!
kclark 02 Apr, 2010
This is what I have tried. I have people that have an ID and the pictures I want to have their ID.jpg. I have tried the following, but it is not working.

$filename = JRequest::getString('ID', 'no_name_entered', 'post');
kclark 04 Apr, 2010
$filename = JRequest::getString('ID', 'no_name_entered', 'post');
I modified this code with this
$filename = JRequest::getString('ID', '', 'post');
and it works only without the extension. How do I get the .jpg extension on the end?
nml375 04 Apr, 2010
Hi kclark,
Try this:
$filename = JRequest::getString('ID', '', 'post') . '.jpg';


/Fredrik
GreyHead 05 Apr, 2010
Hi kclak,

Just adding to Fredrik's post if you have uploads with different suffixes (maybe jpgs and pngs) then you can automate the suffix with
$filename = JRequest::getString('ID', '', 'post') . '.' . JFile::getExt($chronofile['file_0']);
Where ['file_0'] needs to match your file input name.

Bob

PS I'd also suggest that you add a default value in case ID isn't set for some reason like: JRequest::getString('ID', 9999, 'post'). This will avoid any files named '.jpg'.
platipalapi 06 Apr, 2010
just tried; actually if you replace ['file_0'] by the file imput name, it doesn't work.
But it works with
JFile::getExt($chronofile['name'])
GreyHead 06 Apr, 2010
Hi platipalapi,

Apologies, my mistake.

Bob
platipalapi 06 Apr, 2010
1 mistake / 1000+ resolved topics, it's a good ratio, don't worry😉
StingerMKO 16 May, 2010
Hi,
I tried this to put the auto genereated cf_id in front of the date and filename:
$filename = JRequest::getString('cf_id', '', 'post').date('YmdHis').'_'.$chronofile['name'];

It does not work, the first part with the cf_id is not in the filename.
What is wrong?

it should work with other field values out of the form, lile 'text_1' and so on?
Thanks in advance,
Malte
GreyHead 16 May, 2010
Hi malte,

Normally the cf_id isn't created until after the file upload is complete so you can't use it here. It's also not a form input so the JRequest syntax won't find it.

Bob
StingerMKO 16 May, 2010
Ok, thanks.
I removed the cf_id and replaces it with a value of a textfield like

$filename = JRequest::getString('text_2', '', 'post').'_'.date('YmdHis').'_'.$chronofile['name'];


Thanks again!
Great support!!
This topic is locked and no more replies can be posted.