Upload with a special file name

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
A Bindi
Posts: 5
Joined: 2018-01-04 18:45

Upload with a special file name

Post by A Bindi » 2018-11-13 11:28

Hi,

I have a table with a field "File upload" type and I would want upload that file renaming it with a string that is specified in a filed: how can do this ?

ALex.

A Bindi
Posts: 5
Joined: 2018-01-04 18:45

Re: Upload with a special file name

Post by A Bindi » 2018-11-14 07:27

For example, i have two table fields:
- Document (Varchar, 40) - Appgini type "File upload" -> Used to select and upload a file document (.doc/.xls/.pdf ...)
- Filename (Varchar, 120) -> Used to store the new filename I want use for "Document" above

When edit the table:
1) I store the string "Computer user manual" to field Filename
2) I select a file called "SOMETHING.DOC" using field "Document"
3) save the record.

When I open the record and I click on "Document" icon i would want download a file called "Computer user manual.doc".

:)

ALex.

A Bindi
Posts: 5
Joined: 2018-01-04 18:45

Re: Upload with a special file name

Post by A Bindi » 2018-11-19 10:05

No ideas ?
:)

ALex.

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 380
Joined: 2018-04-01 10:12

Re: Upload with a special file name

Post by pböttcher » 2018-11-19 20:34

Hi,

you can try this:

add a function to the hooks/tablename.php file and edit the after_insert and after_update functions:

Code: Select all

function update_filename($id) {
  if (!$_REQUEST['file_remove']) { 
  $dir = getUploadDir($dir);
  $extension=pathinfo($data['Document'], PATHINFO_EXTENSION);
  if ($extension != '') $extension=".".$extension;
  rename($dir."/".$data['Document'], $dir.$data['Filename'].$extension);
  sqlvalue("UPDATE tablename set Document='".$data['Filename'].$extension."' where ID=".$ID']);
  }

}

function tablename_after_insert($data, $memberInfo, &$args){
  update_filename($data['selectedID']);
 return TRUE;
}

function tablename_after_update($data, $memberInfo, &$args){
  update_filename($data['selectedID']);
 return TRUE;
}
replace tablename with your applicable tablename.

Post Reply