Jump to content

Understanding file handling


ptjedi
 Share

Recommended Posts

Greetings,

I wonder if someone can help me with this issue. I am trying to use a file uploaded via backoffice in a template file but with no success. I am using the same sintax as images, but it seems it doesn't work:

$image = $page->images->getRandom(); // this works
$file = $page->files->getRandom(); // this doesn't

I've tried pop(), first() and other functions but I believe I must be missing something.

Thanks for everything.

Link to comment
Share on other sites

I also can't find any example (been looking a lot through the site and forum) regarding file upload and listing them afterward in a page. Could anyone point me in the right direction, please?

Link to comment
Share on other sites

Got it. The problem was related to the fact I only uploaded one file and it seems that when only one file is uploaded, I cannot refer to the field content as an array. This means that this is enough:

$file = $page->files;

I knew this was a simple thing.

Link to comment
Share on other sites

You changed a lot since the last time :D

Glad it's working, but I think it shouldn't work like this. The normal behavior is that it isn't considered an array only if the limit of files is set to one, and not if there's only one file uploaded. Can you check this?

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...