Can files such as PDFs be uploaded to custom URLs? I would like to upload a PDF to www.example.com/whitepapers/pdf.pdf
instead of www.example.com/wp-uploads/...
.
I found a plugin called WP Easy Uploader which seems OK, but I wanted to check if there are any other solutions.
One solution I was contemplating is to have the PDF treated as a page so I can assign a parent page to the PDF. This will handle any redirects in case the URL of the parent page is changed.
UPDATE – Not Considering WP Easy Uploader any more since I don’t want to have any FTP access from within a WordPress installation for security reasons.
Attachments in general (images, but also files like PDFs) have a special “attachment page” of the form example.com/main-post/attachment/file-title/
. In most themes this is used to display a larger version of the image, still in the theme layout (so it returns a HTML file with the image in it, not the image directly).
You could exploit this by creating a template file that does serve the file directly, instead of just displaying it. Then if you create a page example.com/whitepapers/
with an attachment called file.php
, the URL of the file will be example.com/whitepapers/attachment/file
.
You would need to create a file in your theme directory called either attachment.php
(if you want to do this for all attachments) or application.php
(if you only want to do this for files with a mime type like application/*
). In that file you get the attachment file location and then readfile()
it to the browser. I guess there are already plugins out there that can do this for you.