Upload file with custom filename from input form
Upload file with custom filename from input form
Hello, I need to help from you:
I want upload file to server - it is not problem, is working, OK, but I want to ask:
How to set and change:
Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/ID.EXTN' )
I want upload file with manula set filename from input form if I want CREATE RECORD:
Filename: new-york-USA
Datetime: 2016-01-01
Autor: MyName
Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/'.$filename.'-'.$datetime.'-'.$autor.'EXTN' )
Why it is not working?
And uploading file and I want that file was name: new-york-USA-2016-01-01-MyName.pdf
Thank you for help :-)
Ljubo
Answers
Hi Ljubo,
You need to use a custom upload action. The reason the above won't work (unless you do some clever little hacks) is that
$filename
won't be set when the code with it in is executed.There is one additional complication - if you want the file name, etc, to come from Editor input fields, those values aren't submitted to the server when the file is uploaded - only once the form is submitted (and upload happens immediately when the file is selected).
What you might therefore do is store the uploaded file in a temporary location, then move it to the final name when the Editor form is submitted. That could be done with a server-side event -
postEdit
for example.Regards,
Allan