• A new version of Full Calendar is now available.

    See the details here

Placeholder in fileupload-path

wezetel

Active Member
Scenario: simple list with a dropdown field (category) and a fileupload element (picture). When using non-ajax uploads it is possible to use element placeholders in the fileupload-path.

In J3/F3 I used the raw value of the category to be included in the path.
In J5/F4 the raw value doesn't work, instead the placeholder as such is used.

Further investigation:
In J3/F3 even if using the non-raw-placeholder the raw value is included in the path.
In J5/F4 only if using the non-raw placeholder the placeholder works, but includes the raw value (same as in J3/F3)

Summary:
Only raw values of the dropdown are included in the filepath.
For J5/F4 the raw placeholder doesn't work
 
I concur. And I'll add to this, if that's OK.

In J3/F3 you could even use element placeholders in the fileupload directory path WITH Ajax uploads IF you switched on the "Use WiP" option. That worked and still works in a J3/F3 test site I have.
This functionality stopped working in J4/F4, even the very earliest versions.

So in J3/F3, having images/{tablename___element_name} in the fileupload directory path, correctly created a folder named "whatever the element name was" and saved the images there.
In J4/F4 (and J5/F4), this creates a folder actually called "{tablename___element_name}".
(Using a placeholder such as {date} still works though.)

This was a really useful feature for uploading images, so if there's any chance...?
 
In J4/F4 (and J5/F4), this creates a folder actually called "{tablename___element_name}"
I can't confim this statement. If I use "{tablename___element_name}" the folder is created, but with the raw value of the element.
Only if I use "{tablename___element_name_raw}" I get a folder "tablename___element_name_raw".
Maybe this difference in behaviour is depending on the type of the element we are referring to. In my case the element was a dropdown element.

Regarding Ajax: never tested :)
 
Digging up this post old post.

There does appear to be a bug here in fileupload using placeholders.

This is the value of $thumbpath before the following line of code is run.

/home2/xxxxxx/xxx.xxxxxx.com/images/{testing_media___article_title}/

Code:
$thumbPath = $w->parseMessageForPlaceHolder($thumbPath);

This is the value of $thumbpath after the above code.

/home2/xxxxxx/xxx.xxxxxx.com/images//images//

This is in a single group, but stranger things happen in a repeat. I'll look further but need to setup a local F3 environment for comparison.
 
J5.1.2
F4.2 (GitDate 2024-06-26)
Coincidentally, I re-tested this only yesterday and found that the fileupload placeholder now works!

Using the Upload Directory field I can use a placeholder and Fabrik will create a folder with the name of the placeholder and store the images in there. Where the folder already exists (due to previous file uploads), Fabrik puts the new files in there too. Better still, this is regardless of whether or not I'm using Ajax Uploads! I've used this in three different fileupload elements, two without Ajax and one with. All elements are in single groups, however.
 
I forgot to mention on my original post, (it was 4am!), that the issue I was having was on the thumbnails.

Are you creating thumbnails and if so are you using the placeholder code there?
 
Sorry, I’m out at the moment. Yes, as you say, all working including thumbnails. Very happy to have this nice bit of functionality back. Keeps all my files nicely organised!

(Yes, I noticed you posted at 4am!)
 
I performed a number of tests on a clean site and yes it does work as it should.

I have a couple of conflicts happening with a PHP & Article form plugin which also caused unexpected results.


However, the main issue in my case appears to be with the Calc element!! I didn't see it happening as the element was further up the page.

My code returns two placeholders, combines them and then cleans them to produce a filename. This works until you use an apostrophe, (single quote), and then it crashes!!

The javascript side of the calc plugin isn't escaping single or double quotes

Using double quotes around the placeholders is a temporary solution if you only need to use single quotes but of course will crash if you use double quotes!!

EDIT:-

Just to add that this issue exists in J3 as well, so not a new bug.

And it seems that the rename code is what causing the issue with the thumbs when used in combination with placeholders in the upload path.


I think at this stage I'm going to ditch the Calc element and the rename code and do it all via a PHP Plugin.
 
Last edited:
I'm also using a calc element to create the placeholder, but it has successfully handled an apostrophe, both in the calc element and in the folder name created by the fileupload element (see attachments). My calc element code is very basic (like my knowledge) so I can't claim to doing anything clever! It just takes the year from a date field and concatenates it to a text element with spaces removed:
Code:
$ys = strtotime('{ap_all_productions___ap_start_date}');
$y = date('Y',$ys);
$name = str_replace(" ","",('{ap_all_productions___ap_production_name}'));
$mf = $y."_".$name;
return $mf;

I think I'm just lucky it works!
 

Attachments

  • calc element.png
    calc element.png
    7 KB · Views: 62
  • media folder names.png
    media folder names.png
    8.5 KB · Views: 48
What are your Ajax setting on the calc element?

Are you using any observe fields and if so are they surrounded with single or double quotes?
 

Attachments

  • 1724266346515.png
    1724266346515.png
    17.4 KB · Views: 48
All my Ajax settings are No, and I've no observed fields. In fact, I've nothing at all below the calculation field! (I usually set 'Only Calc on Save' to Yes, but I forgot on this calc element - I think I'll leave it as it works ok.)
 
Yes, I think the observation code is causing the problem, at least for this part. The observation field returns the output, (in javascript), but is not being escaped, so an apostrophe kills it. With AJAX of ti doesn't hit this issue.

My thumbs are still going to the wrong location though. I also have two upload elements, one in a single group and the other in a repeat. So I think individually these items work, but certain combinations are too much.

Thanks for the feedback though, it'll be helpful for when I look for a long term fix,
 
Back
Top