johnstephens Posted November 6, 2020 Share Posted November 6, 2020 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 More sharing options...
rick Posted November 6, 2020 Share Posted November 6, 2020 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 More sharing options...
johnstephens Posted November 6, 2020 Author Share Posted November 6, 2020 Thanks, @rick! In my current implementation, I have the file field attached to a repeater, and limited to one upload per repeater item. As a consequence, I'm realizing that the page ID in the path is unique for each file in this case. Thank you for the insight! Cheers! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now