This topic is locked
[SOLVED]

 File/image Upload

2/12/2013 12:14:57 AM
PHPRunner General questions
bbarker author

I saw another posting where someone asked "How can I upload to different folders?".

Some of the responses where "Why would you want to do that?"

So, I thought that I'd answer that BEFORE I asked my question. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=20659&image=1&table=forumtopics' class='bbc_emoticon' alt=':rolleyes:' />
ANSWER: I have a lot of files already stored within various folders and within sub-folders.

I want to continue to use my existing applicationfor users to find these files -- ergo: I need to continue to store them in different folders.
MY QUESTION: My CATEGORY and SubCATEGORY fields are linked as Master and Detail. They contain my FOLDER and SubFolder names.
For the files_add.php page, what do I insert at PHP Expression, so that the Upload Folders works?
Many variations of this hasn't worked.

[size="6"]

$folder = "files/".$values["Category"]."/".$values["SubCategory"]."/";

[/size]

The example given, was

$folder = $_SESSION["UserID"];



Any suggestions?

Sergey Kornilov admin 2/12/2013

In upload folder PHP expression you CAN use any PHP expression or session variable. You CAN NOT reference any fields of the record being added.
If category and subcategory are fields from the Master table you can use one of events like BeforeProcess to save values from master table to session variables. Then you can use PHP expression like this one:

$folder = "files/".$_SESSION["Category"]."/".$_SESSION["SubCategory"];


Another, more complicated approach, is to upload files to some common directory first and then move them to any folder you need manually in AfterAdd/AfterEdit events. Do not use this approach unless you MUST use one of user entered fields as a folder name.

bbarker author 2/12/2013



You CAN NOT reference any fields of the record being added.


Thanks Sergey... The sentence above is exactly what I tried to find -- and needed to know.
I thought about creating the Session variables but thought that it might be to much "overhead"... eg. 10 categories with 10 subcategories each equals 100 session variables.

But it looks like that's the best way. I'll give it a whirl.

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=69792&image=1&table=forumreplies' class='bbc_emoticon' alt=':D' />

Sergey Kornilov admin 2/12/2013

Something is not right if you are going to create a hundred of session variables. You only need two variables, one for category and another one is for subcategory.