ข้ามไปยังเนื้อหาหลัก
หน้าแรก
DrupalThailand

Main navigation

  • หน้าแรก
  • ฟอรั่ม
  • ประกาศงาน
  • บทความ
  • กิจกรรม
User account menu
  • เข้าสู่ระบบ

การแสดงเส้นทาง

  1. หน้าแรก
  2. บทความ

Drupal 8 Entity API cheat sheet (Part 2)

By admin, 5 สิงหาคม, 2021

การทำงานกับ ไฟล์  (File entities)

วิธีส่งค่าไฟล์ออกมาด้วย fid ใน Drupal:

$fid = 31;      // ตัวอย่าง fid
$file_storage = \Drupal::entityTypeManager()->getStorage('file');
$file = $file_storage->load($fid);

การแสดงค่า ออกจากตัวแปร

echo $file->getFileUri();   // "public://filetest.jpg"
// หากคุณต้องการ URL ที่ไม่ในรูปแบบของ​​ Drupal ที่กำหนด คุณสามารถแปลเป็น URL ธรรมดาได้:
echo file_url_transform_relative(file_create_url($file->getFileUri()));   // "/sites/default/files/public/filetest.jpg"
echo $file->filename->value;   // "filetest.jpg"
echo $file->filemime->value;   // "image/jpeg"
echo $file->filesize->value;   // 63619  (size in bytes)
echo $file->created->value;    // 1592206249  (Unix timestamp)
echo $file->changed->value;    // 1592234256  (Unix timestamp)
echo $file->id();              // 31

 

Tags

  • drupal8
  • api
  • drupal
  • Log in or register to post comments

Comments

Releases for Drupal core

drupal 9.3.17

Releases for Drupal core

drupal 9.4.1

Releases for Drupal core

drupal 10.1.x-dev

Releases for Drupal core
More posts about Releases for Drupal core

Tags

  • ธีม
  • docker
  • css
  • mac
  • drupal8
Powered by Drupal Thailand