This topic is locked

custom upload folder using php expression

2/7/2023 5:40:22 PM
PHPRunner General questions
1NET author

I am trying to upload files into a custom directory based on information that relates to the current record, ie.

I have a job for a client "xyz industries" - field on the edit page is: account_name
I also have a job_address field which is populated on the edit page "1 Happy Street"
I am uploading photos & documents to the measure & quote section of this job

so in my custom upload path i am wanting to achieve the directory structure of: {server root]/files/xyz industries/1 Happy Street/Measure & Quote/

the php needs to create the file directories if they dont yet exist.

I have tried

$folder = 'files/'.$_SESSION["account_name"].'/'.$_SESSION["job_address"].'/Measure & Quote/';

and

$folder = 'files/'.$data["account_name"].'/'.$data["job_address"].'/Measure & Quote/';

which do not work and cannot seem to display the values of account_name or job_address

All examples are using an ID which i dont want a directory created using a number value, I need words "xyx industries"

admin 2/9/2023

The approach with sessin variables will work, just make sure that those session variables are populated before Add or Edit page is loaded.

I would also avoid using characters like & and spaces in folder names.

fhumanes 2/9/2023

Hello,

As Sergey explains, if you have the information that the path of the directory will form, before uploading the file, it will not have more problems than defining names of directories that fit the characteristics of the operating system where the application.

If the directory is created with information from the registration fields used to upload the files, this will not be possible.

In this example: https://fhumanes.com/blog/gestor-de-proyectos/sistema-de-archivo-de-documentos-electronicos-edas/
Where the directory is created by registration information in which the files are uploaded, what I do is:

  • Define a temporary directory where all files are uploaded.
  • In the event "AFTER ADD/EDIT", what I do is to move the files of the temporary dirt to the final directory.

I think that in the example you will facilitate knowledge to solve your problem.

Greetings,
fernando