4

My site is in sites/sandbox folder. When I upload to live server, this will change to sites/mysite

In file system settings, the public file system path is set to sites/sandbox/files. When site goes live, I plan to change this to sites/mysite/files

File module is enabled and I am uploading PDF files. When entering content, how can I link to an uploaded file using a relative path that won't break when the site goes live?

Or perhaps the site directory name ('sandbox') should never be changed?

3

The Pathologic module will fix all of that for you automatically when you move it over

Pathologic is an input filter which can correct paths in links and images in your Drupal content in situations which would otherwise cause them to “break;” for example, if the URL of the site changes, or the content was moved to a different server. Pathologic can also solve the problem of missing images and broken links in your site’s RSS feeds. See more example use cases on the documentation page.

  • Thanks - this is a nice solution. I had to use latest dev release and add 'files:' before relative URL and everything works great. – pushka Jun 19 '11 at 10:06
4

Did you try file_create_url() ?

$file_uri = file_create_url(file_build_uri('images/example.jpeg'));

The above snippet will give the file URL. Besides, I recommend transliteration module for the sites that deals with file uploads.

1

Use base_path() (function) OR $base_path (global var) that will result /sites/mysites OR /sites/sandbox for your sites. Always use it in themes and every where. This will give you ease to sync both sites with any edit.

Links can be produced

l('Link Title', base_path() . "/files/filename.ext");

OR

global $base_path;
l('Link Title', $base_path . "/files/filename.ext");
  • Thanks for the detailed answer. I should have explained the question better: I create a node and upload a PDF file using File field. There is an option to display a download link automatically, but I want to manually hyperlink some text in the body field. So I have to include "sites/sandbox/files/..." in the link URL, and that will change when site goes live. It would be good to avoid entering PHP in the body if at all possible. – pushka Jun 18 '11 at 10:47
0

The LinkIt module is a pretty comprehensive solution for inserting links into fields and wysiwygs in really any format you choose. I'm using File Entity and Media and using the LinkIt WYSIWYG integration allows me to insert links to files however I'd like, including direct links to the file for the desired "open in browser" behavior. It's also got a great autocomplete search function for finding nodes or files. I wish I had found it sooner.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.