hello,
Thank you for the great module.
I have a 3 language website. I use i18n module for that.

for Romanian language the link looks like this:
http://local-website/system/files_force/pricelists/pricelist-2013-01-16-...
The link above doesn't work. Because it misses the language prefix before "/system".
I get the following message: Access denied. You are not authorized to access this page. Also i see this error:

Warning: Invalid argument supplied for foreach() in file_file_download() (line 177 of X:\xampp-sites\local-website\modules\file\file.module).

If i add the "ro" prefix, the file force works well.
So, the correct link should be the following:
http://local-website/ro/system/files_force/pricelists/pricelist-2013-01-16-ro.pdf?download=1

Please investigate this problem.
Updated on 27 May 2013:
Drupal version: 7.22
File system: public
I create the link using views. Formatter: File Force: Generic file.
I have not configured any permissions for file force. But, since it works for english language (english doesn't have a prefix), i think it's not a permission problem.

Modules:
File Force Download 7.x-1.2
Views 7.x-3.7
Theme: Omega 7.x-3.1
Internationalization 7.x-1.8
Global Redirect 7.x-1.5

I tested the error with firefox, opera and chrome. So it doesn't rely on browser.
The error appears for user1 and for anonymous users too.

Thank you
Andrew

Comments

intyms’s picture

A solution is to change the function file_force_create_url
The are 2 changes:

function file_force_create_url($path, $add_query = TRUE) {
  global $language; // first change
  if (empty($path)) {
    return '';
  }
  $scheme = file_uri_scheme($path);
  if ($scheme == 'public') {
    $url = file_create_url((isset($language->prefix) & ($language->prefix <>'')) ? ($language->prefix . '/system/files_force/' . file_uri_target($path)) : ('system/files_force/' . file_uri_target($path))); // second change
  }
  else {
    $url = file_create_url($path);
  }
  if ($add_query) {
    // '&' for private uploads in non-clean URLs. Public downloads or clean URLs need '?' as there is no query.
    $separator = (variable_get('clean_url', FALSE) || ($scheme == 'public')) ? '?' : '&';
    $url .= $separator . 'download=1';
  }
  return $url;
}
intyms’s picture

Status: Active » Needs review
StatusFileSize
new789 bytes

The patch file is attached.

arski’s picture

Hmm, this looks a bit wrong indeed, but I'm not quite sure about one thing - you say it works for English without a prefix, but then you say that in Romanian language you get access denied without the prefix. So I'm assuming it's exactly the same file link in both languages, but it works only if you're currently browsing in English, is that correct?

Because I'm testing it and indeed my file link does not have a prefix, but it still work regardless of what language I'm browsing in.

intyms’s picture

Hello,
Thanks for looking at this issue:

I uploaded different files for these languages.

So, the generated url for the Romanian language is the following:
http://local-website/system/files_force/pricelists/pricelist-2013-01-16-RO.pdf?download=1

and for English language:
http://local-website/system/files_force/pricelists/pricelist-2013-01-16-EN.pdf?download=1

Both urls doesn't have a prefix. The English link works (i didn't set a prefix for English in i18n settings).
But, the Romanian link doesn't work. The url that works is the following:
http://local-website/ro/system/files_force/pricelists/pricelist-2013-01-16-RO.pdf?download=1

Let me know if i missed something,

Best regards,
Andrew

arski’s picture

OK, where did you upload the two different files? Is it one object that is translated, or two different ones with a language set? I'm trying to understand how does Drupal figure out which of the files should be Romanian (the different file names are basically irrelevant).

intyms’s picture

Settings related to content type
I have created a content type called "Pricelist".
And configured the multilingual support according to the screenshot "1 multilingual support" and "2 multilingual support". See attached files please.
Then i added a "File" field type to Pricelist. See attched screenshot "3 upload pricelist field".
The field settings are shown in the image "4 field settings".
Settings related to /admin/config/regional/language
See screenshots:
"5 multilingual website settings"
"6 multilingual website settings - ENGLISH language"
"7 multilingual website settings - ROMANIAN language"
As you can see, i didn't set a path prefix for English language. But there is one for Romanian language.
Adding content
I have added a new content to Pricelist content type.
See atteched file "8 Adding English content".
"9 English content"
Then i press translate button and create a Romanian translation.
See attached "10 Translating content to Romanian".
So, at this step we have 2 nodes. One for English language and another for Romanian.
Check the file link which is create by drupal
For english node: "11 Checking the English file link created by drupal"
For romanian node: "12 Checking the Romanian file link created by drupal"
As you can see drupal doesn't place any prefix to the Romanian link.
Let's test now the file force link:
For english file link I write the following URL in the address bar: "mywebsite/system/files_force/pricelists/en_test.pdf?download=1"
And it works. The file is downloaded.
For romanian file link i write the following URL in the address bar: "mywebsite/system/files_force/pricelists/ro_test.pdf?download=1"
And it doens't work. I get the error: "13 error downloading RO file"
Now, let's add RO prefix to the link. So the final URL will be: "mywebsite/ro/system/files_force/pricelists/ro_test.pdf?download=1"
And it works, so the file is downloaded.

Hope this information helps. let me know if you need other information.

intyms’s picture

Issue summary: View changes

Added drupal and modules versions.
Added a little bit more details.

sebastix’s picture

I encountered the problem that the file link (file_protected) field in a i18n view was redirecting to the default language of the website (and that link gave a access denied error).

Fixed this problem with patch-2004692-1.patch from comment #2.