charger Posted March 30, 2015 Share Posted March 30, 2015 I need assets (PDF files) from multiple pages to be accessible from a single URL. That means, instead of http://www.domain.com/assets/files/1011/example1.pdf http://www.domain.com/assets/files/1012/example2.pdf ... it should be e.g. http://www.domain.com/assets/files/example1.pdf http://www.domain.com/assets/files/example2.pdf ... so without the page ID in the URL. The reason I need it this way, is because: I can't use a single page to save all files (PDFs) in it, as there are additional fields to every PDF. That means I need PageTable or Repeater, and both create new pages for every PDF There's a 3rd party service that links from external pages to the PDFs. That service however doesn't know about the page ID in the URLs, it only knows the filename of the PDFs. I've found the following topics in the forum that somewhat touch my subject, but I couldn't make them work for me: https://processwire.com/talk/topic/8312-creating-my-own-folders-for-image-assets/ https://processwire.com/talk/topic/4127-can-assets-folder-be-moved-to-another-domainsubdomain/ Any idea on how I could solve this? Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted March 30, 2015 Share Posted March 30, 2015 I found this topic. Looks related and Ryan answers... I thought there was a module to manage assets the way you described, but could not find it. Maybe I was just dreaming) Link to comment Share on other sites More sharing options...
Jan Romero Posted March 30, 2015 Share Posted March 30, 2015 As long as you don’t need to physically store the files in one central directory, I’d create a page that accepts the file names as urlSegments, and serve them from there. The file names would have to be unique anyway for your proposal to work, so you should have no problem fetching them. The only problem would be that this solution does not guarantee unique upload file names, because the files would still be in separate directories. You could ignore this or hook into the file upload somewhere to make sure. E. g. you may do this: $filename = $sanitizer->selectorValue($input->urlSegment1); $p = $pages->get('images=' . $filename); if ($p->id > 0) header('Location: ' . $p->images->get($filename)->url); else throw new Wire404Exception(); die(); Bit crude but you get the idea. 2 Link to comment Share on other sites More sharing options...
charger Posted April 17, 2015 Author Share Posted April 17, 2015 Thanks for your answers, I've used the following (slightly modified code) in my template to get it work: if(!$input->urlSegment1) throw new WireException(); // check for url segment $filename = $sanitizer->pageName($input->urlSegment1); // sanitize url segment (filename) $p = $pages->get("files=$filename"); // search all pages for $filename in field files if(!$p->id) throw new Wire404Exception(); // check if page exists $session->redirect($pages->get($p->id)->job_pdf->url); // redirect to file For some reason, the additional viewable() check for $p always resulted in a 404 error. So I removed it. 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