Jump to content

How to retrieve file ID from item uploaded by fieldtype file


johnstephens
 Share

Recommended Posts

Hi!

I'm trying to retrieve a unique identifier of a file uploaded by a file fieldtype. For articles, I can simply use $page->id, but that doesn't work for files. $page->url and $page->file->url both give the the URL, by contrast.

Suppose I have a file uploaded to "/site/assets/files/11067/test.pdf". The number "11067" would have to be unique. Is there any way to get that number using the API?

The immediate problem is I need an identifier I can append to an HTML id attribute for interaction with JavaScript. <a id="D11067">, for example, would work fine.

Thanks in advance!

Link to comment
Share on other sites

Hi @johnstephens,

The reference to 11067 in your path represents the page id, so you can't create your own identifiers for the folder names and have them each refer to the same processwire page. But since your application is using the current page ($page->id) you could either create unique filenames or add a unique identifier as a tag to each file, then reference the filename (or tag) for inclusion in the attribute. Using tags might be the simplest route if there are no other tags being used. If there are other tags, you might want to use a custom field for those files as your reference point.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...