2012-04-05 14 views
1

多言語サイトでDrupalのアップロードパスに問題があります。 新しい言語を作成しました。イメージのソースにバックスラッシュがないため、機能しません。マルチ言語サイトのDrupalアップロードパス

私の関数は次のコードを使用します。

variable_get('file_public_path', drupal_get_path('theme', $theme) . '/uploads').'/'; 

次のコードを使用すると動作します。

'/' . variable_get('file_public_path', drupal_get_path('theme', $theme) . '/uploads').'/'; 

これは一種の醜い解決策であり、これに対処するためのもっとエレガントな方法があります。

答えて

1

パブリックパスに保存されている画像のURLを取得するコードの代わりに、以下のものがあります。 (正しいファイル名を指定して「image.png」を交換してください。)

$image_url = file_create_url(variable_get('file_public_path', conf_path() . '/files') . '/image.png'); 

をあなたのコードでは、そうでない場合は、パスがサーバーのドキュメントディレクトリからの相対とみなされていない、先頭にスラッシュを使用する必要があります。
Drupalサイトの言語としてイタリア語を有効にした場合、そのページのURLはhttp://example.com/it/pageで、イメージはsites/default/files/image.pngに保存されます。スラッシュがなければ、画像URLはブラウザからはhttp://example.com/it/sites/default/files/image.pngとみなされます。スラッシュを使用して、画像URLはブラウザからhttp://example.com/sites/default/files/image.pngとみなされます。

「file_public_path」Drupal変数のデフォルト値はvariable_get('file_public_path', conf_path() . '/files'である必要があります。これがsystem_file_system_settings()で使用されるデフォルト値です。

$form['file_public_path'] = array(
    '#type' => 'textfield', 
    '#title' => t('Public file system path'), 
    '#default_value' => variable_get('file_public_path', conf_path() . '/files'), 
    '#maxlength' => 255, 
    '#description' => t('A local file system path where public files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web.'), 
    '#after_build' => array('system_check_directory'), 
); 
関連する問題