Forums

How to pass Upload Directory by variable in ChronoForm8?

umbcel 31 Aug, 2023
Hi guys,
I am trying to migrate a form that upload an image on the server.
The file to upload must be saved in one of two differents directory depending on whether the user is registered or not.

If the user isn't logged then the file must be saved in "custom_path"\guests directory.
If the user is registered and logged the file must be saved in "custom_path"\<username> directory.

I added on top of the form some PHP lines like that:

<?php
$jid = JFactory::getUser()->id;
$jusername = JFactory::getUser()->username;
$directorypath = $_SERVER['DOCUMENT_ROOT'] . "/images/custompath/";

if($jid > 0) {
 $directoryName = $jusername;
}
else {
 $directoryName = "guests";
}

if(!is_dir($directorypath.$directoryName)){
    mkdir($directorypath.$directoryName, 0755);
}
$fullPath = $directorypath . $directoryName."/";
$fullPathW = str_replace("/", "\\", $fullPath);
$this->set("userdir", $fullPathW);
?>


I tried to put {var:userdir} in the Upload Directory field but file isn't uploaded.
If I manually write the whole same url in Upload Directory the file is uploaded.

How should I do to solve this problem?
Max_admin 31 Aug, 2023
enable the form debug and check the debug results, what does it show ? it should show the file full path or an error
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
umbcel 31 Aug, 2023
Hi Max,
I enabled form debug and before submit are displayed some data like that:

Data

Array
(
    [chronoform] => invia-render
)

Files

Array
(
)

Vars

Array
(
    [app_active_page] => 0
    [usrdir] => <correct absolute path>\<username, because I am logged>\
    [security_recaptcha23] => true
)

Info

Array
(
)

After Submit nothing is displayed.
I also checked server PHP error log and no one error is here.
Max_admin 01 Sep, 2023
what's important is the debug after the form is submitted, you have just one page in your form, correct ?

please post here the debug after submit
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
umbcel 01 Sep, 2023
Hi Max,
after Submit no debug info is displayed.
Max_admin 01 Sep, 2023
nothing at all ? there should be some "Data" and "Files" at least
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
umbcel 01 Sep, 2023
Yes Max, nothing at all and nothing at all also in PHP error log.
Max_admin 01 Sep, 2023
do you have a redirect in your form ? there should be a debug under every page if debug is enabled
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
umbcel 01 Sep, 2023
Hi Max,
there was no log after Submit because the option "Ajax Form" was set.

So, now I am able to get form log and the result is:

Debug
Data

Array
(
    [chronoform] => invia-render
    [nominativo] => Umberto Celentano
    [email] => <my email>
    [titolo] => jkhkjhkh
    [link_artista] => 
    [render_engine] => cycles
    [approvazione_privacy] => Accetto il trattamento dei dati personali
    [dichiarazione_di_responsabilita] => Conferma dichiarazione di responsabilità e la liberatoria per l'uso dell'immagine inviata
    [g-recaptcha-response] => 03ADUVZwDA6RKuv4E3O1fngmjOk4AtCSZuxu97-oWVrHPVMB3qpQdoFZcijxka5qk2MTOhTl5bBaptdVs_ay-kwqu8GvTs4T0BogtSfrtHhXszzMHNiJMwiL1b1rSA9Ms6Svlw4t6hcRz8W-H3X-rEYvfYVd2RuWN4esGlbeG75_2k2RXCpAsrHN9EHZCHjROIuOAHP-9887By3uXZfLHtmyPoHADjfuf06fU4EspAF1fXfwLhCYd2zzL4Lh5ftkKMjhhkkmw9yIF_PLcuM00IGjdAO7OH1ZQBL5c7dLH4uq3Kyne-noDsWHeo9ruNGy6SEtqYbg1uBzbEah6vfdrIOvqjJcJlSSpmY9Jm42O4AtRsyW1ks5ltapNjIcMKSlsoDXRpIs4M9flCE-QkZCAnmV1xocDUFTWfeTxFxktsDgIZUabwT6Blff9yL5BFoIpAyzXnboAzr5GEDfAZPCGfhvOaWEi4dXDQzLpPHW8_EidH_wp7yOxw-0sN1uGHIb0KmW-CKdWIb3GVYJ0KuWh-c8gxNIrGYc2yAEzTbmv6S9B2BUf9kzOjWx0
    [invia] => 
    [chronopage] => 0
    [sectoken] => 64f21bcaf01287.96586750
)

Files

Array
(
    [immagine] => Array
        (
            [name] => IMG-20190507-WA0004.jpg
            [full_path] => IMG-20190507-WA0004.jpg
            [type] => image/jpeg
            [tmp_name] => <path temp file>\php46CD.tmp
            [error] => 0
            [size] => 81925
        )

)

Vars

Array
(
    [app_active_page] => 0
    [usrdir] => <the correct absolute path>
    [security_recaptcha23] => true
)

Info

Array
(
    [security_recaptcha23] => Array
        (
            [response] => Array
                (
                    [success] => true
                    [challenge_ts] => 2023-09-01T17:13:55Z
                    [hostname] => blenderartists.it
                )

        )

    [field_file7] => Array
        (
            [error] => Upload dir not available: 
        )

)


Then I wrote the same Upload Directory Path manually in the field and the form run fine but not like I want:

Debug
Data

Array
(
    [chronoform] => invia-render
    [nominativo] => Umberto Celentano
    [email] => <my email>
    [titolo] => jkhkjhkh
    [link_artista] => 
    [render_engine] => cycles
    [approvazione_privacy] => Accetto il trattamento dei dati personali
    [dichiarazione_di_responsabilita] => Conferma dichiarazione di responsabilità e la liberatoria per l'uso dell'immagine inviata
    [g-recaptcha-response] => 03ADUVZwBLocSzOlaNiskQxiZdTef52Y1fiwKnepIBqYUAImHdKSSjO4Tv4W-V8PdzNwrM02e6ITXmxpXPG5zuS5Nk-um-JvH7G5GjZGn3CdYLoYI8_2rtp1JrH2DNR2pgo3iN0WiQdcvtLhyzXwzIzHJXF_VOEi8Nap6-9rLtVVPIkQVuNI5v2DrICRpkEPxf5Szofvq5Xfgf8iZFPvjYzJIPjo8fNO4Vc_Zww5XqWmBEg4wK4F-uTNOJBrzQ04BZ1lAsY7Sw9hRNZ4RqagJnLeWm3_AgboPVgDoNOfRHnjQQ5cDDfBM2rnNfnNn-RLgxiO8231SLVEeIQ6AmdKG4G2JGdt6KyHiTzfF0uLpKFIfmGNFPC35ANz9W28TDw4cQn5K5IH3emmn0onp0oZ6h2WeI8SBu7k62EjBJjMK6RjCv8vnV9RAttU5oucfFo0RbCj8KUY10uciCbfVlYYhJXfn7jfDHJJKQj_KA_agzRmxxOT8jUAxN1I8Xhx1dZ7YDMVnwk53i61d7bTylRwY3fhreaFRKKFwLG13ZguhZMAs_xI7xsDI7uSY
    [invia] => 
    [chronopage] => 0
    [sectoken] => 64f21efd79efd7.17209978
    [immagine] => img-20190507-wa0004_20230901_172754.jpg
)

Files

Array
(
    [immagine] => Array
        (
            [name] => IMG-20190507-WA0004.jpg
            [full_path] => IMG-20190507-WA0004.jpg
            [type] => image/jpeg
            [tmp_name] => <temp path>\phpF95C.tmp
            [error] => 0
            [size] => 81925
        )

)

Vars

Array
(
    [app_active_page] => 0
    [usrdir] => <the same url but written manually>
    [security_recaptcha23] => true
    [field_file7_upload] => Array
        (
            [path] => <the same url but written manually>img-20190507-wa0004_20230901_172754.jpg
        )

    [userdir] => <the same url calculated by another indentical PHP block on top of Submit Actions with double \\ as dir separator><username>\\
    [php25] => NULL
    [email17] => true
    [email18] => true
)

Info

Array
(
    [security_recaptcha23] => Array
        (
            [response] => Array
                (
                    [success] => true
                    [challenge_ts] => 2023-09-01T17:27:33Z
                    [hostname] => blenderartists.it
                )

        )

    [field_file7] => Array
        (
            [success] => Array
                (
                    [0] => File IMG-20190507-WA0004.jpg was uploaded to <the same url but written manually>img-20190507-wa0004_20230901_172754.jpg
                )

        )

    [php25] => Array
        (
            [returned] => NULL
        )

    [email17] => Array
        (
            [status] => true
            [recipients] => Array
                (
                    [0] => <my email>
                )

            [subject] => Nuovo rendering inviato!
            [content] => <email content>
            [attachments] => Array
                (
                )

        )

    [email18] => Array
        (
            [status] => true
            [recipients] => Array
                (
                    [0] => <another email>t
                )

            [subject] => Nuovo rendering ricevuto!
            [content] => <another email content>
            [attachments] => Array
                (
                    [0] => <the same url calculated by another indentical PHP block on top of Submit Actions with double \\ as dir separator>\\img-20190507-wa0004_20230901_172754.jpg
                )

        )

)


To better debug the problem and for security reason can I send to you, privately, a backup of the form?
How to?

Thank you so much for helping,

Umberto
Max_admin 01 Sep, 2023
The error at the first try was just like that:
[error] => Upload dir not available: 

?
nothing after that ? because this means the path is not passed.

Where did you place your PHP code ? it should be on the "submit" event
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
umbcel 02 Sep, 2023
Hi Max,
the PHP code is placed at the top of the form Load.
Initially I had used an HTML field and in "Behaviors" I had selected "Run PHP" then I replaced it with the "PHP" field present in "Action".
I placed the same PHP code also in Submit to pass variable to EMAIL field to attach the file to a notification message.
Below the screenshot of my form configuration, not in details but only to see the structure.

Max_admin 06 Sep, 2023
you need PHP actions as you have now, and your PHP code should be "without" PHP tags, is this how its now ?

Does it work or not ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
umbcel 06 Sep, 2023
Hi Max,
PHP code work in both cases.
Max_admin 08 Sep, 2023
so now all is good ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
umbcel 08 Sep, 2023
No Max,
Php code work but form not work.
Please can I send a backup to you to test yourself?
Max_admin 08 Sep, 2023
is the folder created when the PHP code runs in the form ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
umbcel 09 Sep, 2023

Max_admin posted Sep 8, 2023 at 22:13
is the folder created when the PHP code runs in the form ?


If the folder not exist yes but in my case the folder just exist.
Please, give a look to the PHP code i posted above.
Max_admin 11 Sep, 2023
the folder has to exist before the Email action runs, that's all, is this how your form is setup ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
umbcel 12 Sep, 2023
but is it me who can't express myself well or are you kidding me? I told you clearly that the folder already exists so it cannot be a problem resulting from its creation.
Furthermore, the folder in question is created immediately, if necessary, before the action of sending the form, as can be seen from the PHP code I posted. Now I would like to know if you are going to solve my problem or if I have to opt for another solution to create forms in Joomla. I'm tired of this ping pong of useless messages.
Max_admin 13 Sep, 2023
Answer
Ok, the path to upload should exist when the form is submitted, it may include shortcodes {data/user...etc} but not custom vars like {var:userid}

So, to do what you want, run your PHP in "load", then, in your file field settings, use the static path with the core shortcodes:
/images/custompath/{user:id}/

guests will have files saved under directory "0"

this is because the upload code runs BEFORE the actions in the "submit", so your variable is not available, and the path should be available.

Another solution is to use {session:var_name}, this way you can store the variable in the session after you create it and call it in the path later, but the "session" shortcode can be used starting from the next update.

you will need to use this code in your PHP to set the var:
ChronoSession::set("userid", 123);

then use this shortcode to get it in the path:
{session:userid}
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
umbcel 14 Sep, 2023
Ahhhh, finally a comprehensive answer. Did it take that long for you to say it first?
Thank you so much, I'll try asap.
You need to login to be able to post a reply.