ノードに埋め込んだファイルのURLアドレスを取得する

ファイルへのパスを取得するには、file_create_url() を使用します。

たとえば Drupal 7 コアに含まれるファイルアップロード機能とイメージハンドリング機能を使った場合、1つ目のイメージファイルへの URI は node オブジェクトの中に以下のように格納されています。

$node->field_image['und'][0]['und']

そこで、この情報を元にこのファイルへの URL アドレスを取得するには、


$uri = $node->field_media_image['und'][0]['uri'];
$image_path = file_create_url($uri);

というコードを使えばいいことになります。

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.