Change the name of the uploaded file

Change the name of the uploaded file

szakendreszakendre Posts: 24Questions: 10Answers: 0

Hello,

I use the file uploading function almost all of my projects.
I use the following code:
https://editor.datatables.net/examples/advanced/upload-many.html

Right now the filename is the ID of the file table, which is a AI INT. For example:
ID: 7
filename: pr-edp-1001.pdf
filesize: 1047119
web_path: /upload/7.pdf
system_path: /var/www/pr//upload/7.pdf

I would like to change this to contain the original filename.
I know that this has to be unique, so the web_path and system_path sould be the ID + '-' + original filename:
7-pr-edp-1001.pdf

How can I acieve this?

Thank you and best regards:
Endre, Szak

Answers

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin

    Hi Endre,

    If you have a look at the PHP controller for that file it uses:

    ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/upload/__ID__.__EXTN__' )
    

    If you have a look at the documentation here you will be able to see that you can use __NAME__ as well as __ID__ to achieve what you are looking for.

    Allan

  • szakendreszakendre Posts: 24Questions: 10Answers: 0
    edited July 2020

    Hi Allan,

    Perfect, I use the '/upload/__ID__.__NAME__' format.
    It works like a charm.

    Thank You and best regards:
    Endre, Szak

This discussion has been closed.