Append Field Value to Filename

Talk about Image/File fields (uploading, problems etc.)

Moderator: alexandrleonenko

cateappstech
Junior
Junior
Posts: 11
Joined: Feb 3rd, '12, 12:12

Append Field Value to Filename

Postby cateappstech » Feb 10th, '12, 03:55

After reading the forum I am getting snippets that I can't quite piece together, so I am going to ask for help.

I have a data column called: product_code

I only add images in 'edit' mode so that the product_code already exists.

If for example product_code = "doll", I wish to be able to identify images easily, so I would like the filename to be "doll-imagename.jpg"

(Note: this is only an example, so its not a case of just typing in "doll-imagname.jpg" :D )

I am sure this can be done simply... Please tell me the efficient way to do this

Thanks

administrator
Site Admin
Site Admin
Posts: 6010
Joined: Jan 7th, '09, 23:18
Contact:

Re: Append Field Value to Filename

Postby administrator » Feb 12th, '12, 08:16


harryo
Newbie
Newbie
Posts: 7
Joined: Feb 2nd, '09, 17:26

Re: Append Field Value to Filename

Postby harryo » Jun 21st, '12, 17:23

Hello,

This is appending to a string, which works great! But can you also append a field value to the original uploaded filename? For example:

The file uploaded is: myDoc.pdf

I would like to save as myDoc_1234.pdf where "1234" is the value of another field. So I can retain the original filename.

Can this be done?

Thank you!

administrator
Site Admin
Site Admin
Posts: 6010
Joined: Jan 7th, '09, 23:18
Contact:

Re: Append Field Value to Filename

Postby administrator » Jun 21st, '12, 20:14

Yes, try following:
Set unique value for uploaded image:

a) 'file_name'=>'img_'.((isset($_GET[$unique_prefix.'mode']) && ($_GET[$unique_prefix.'mode'] == 'add')) ? $dgrid->GetNextId() : $dgrid->GetCurrentId())

b) 'file_name'=>'img_'.((isset($_GET[$unique_prefix.'mode']) && ($_GET[$unique_prefix.'mode'] == 'add')) ? $dgrid->GetRandomString('10') : $dgrid->GetRandomString('10'))


Return to “Field type: "image/file"”