Dynamic upload folder creating issue

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
anil
User
Posts: 24

Dynamic upload folder creating issue

Post by anil »

I have set a field setup like this in "Field Setup -> Edit Tag -> File -> Upload folder"

when i use below code, subfolder is creating and file is going inside that. But when i edit the record, edit page shows File not found.

"uploads/" .$this->UPLOAD_FIELD_NAME->CurrentValue."/"

When I use below code, subfolder itself not creating. File is saving into 'uploads' folder itself.

"uploads/" .$this->UPLOAD_FIELD_NAME->DbValue."/"

How to solve above two?


mandlipalli
User
Posts: 11

Post by mandlipalli »

i want Dynamic folder when i upload a file.for example if i upload file, it should save like( C:/wamp/WWW/MAIN FILE FOLDER/dyanmic folders ).
i used this code in "Field Setup -> Edit Tags -> File -> Upload" .$this->UPLOAD_FIELD_NAME->DbValue. but doesnt work and it is uploading file in main folder itself.

i have tried all the given possible ways but nothing is working out and i didnt get the solution. i am using 2018v. Pls help me out. Thanks


arbei
User
Posts: 9288

Post by arbei »

when i use below code, subfolder is creating and file is going inside that. But when i edit the record, edit page shows File not found.
"uploads/" .$this->UPLOAD_FIELD_NAME->CurrentValue."/"

The folder name should better not have the dot and the extensions, you can change the folder name to the filename without the extensions.

For example:
"uploads/" .substr($this->UPLOAD_FIELD_NAME->CurrentValue, 0, strrpos($this->UPLOAD_FIELD_NAME->CurrentValue,"."));

When I use below code, subfolder itself not creating. File is saving into 'uploads' folder itself.
"uploads/" .$this->UPLOAD_FIELD_NAME->DbValue."/"

If you refer to the Update() method of the generated code, the DbValue does not available in the update process, so your folder name becomes empty.

You can use $this-><Field>->Upload->FileName to get the uploaded file name during update. But in View Page or List Page, $this-><Field>->Upload->FileName will not have value, So you cannot get the correct folder name.

So you better write a global function (placed in server side Global Code) to get the filename in the different situation and then return it to the folder path.

For example: (Note: assume not multiple upload)

function functionname() {
$page = CurrentPage();
if ($page->IsInsert() || $page->IsUpdate()) {
$filename = $page-><Field>->Upload->FileName;
} else {
$filename = $page-><Field>->CurrentValue;
}
return substr($filename, 0, strrpos($filename,"."))
}

Then you can setup the folder path as : "upload/" . functionname() . "/";

But the better way is not to use the filename as the dynamic folder name as the folder will unnecessarily varies with the file name.


mandlipalli
User
Posts: 11

Post by mandlipalli »

Thanks for help...It works


napalm
User
Posts: 14

Post by napalm »

this is very interesting.

How can I have uploaded files inside uploads/ID/filename.ext if ID not exist on Add ?


bioaroma
User
Posts: 24

Post by bioaroma »

It seems that this is for old version pf phpmaker

I want to save files in folder that are created dinamically
Let say I have mysql table

name varchar 255 [John]
file varchar 255 [documents_of_john.pdf]
Can you tell me for new phpmaker how to save files in location like this

/folder/name/file
(that is stored in name field of mysql table mentioned above)
more precisely the folder structure will be like this
/folder/John/documents_of_john.pdf
Can you tell me what should I add in the path of the folder?


Post Reply