- concrete5 Cookbook
- David Strack
- 250字
- 2021-08-13 16:16:03
Loading a file by its ID
The most common interaction with files for most concrete5 developers is loading files and interacting with them. To do this, we must load a file by its ID. The code in this recipe can be placed wherever you need to load a file and retrieve or modify its attributes.
Getting ready
We will need to know the ID of the file that we are loading. In this recipe, we will load a file with the ID of 17
. If your concrete5 site does not have a file with an ID of 17
, upload a new file to the file manager and change the ID in this recipe to match the ID of the newly uploaded file. You can get the ID of a file by visiting the file manager, clicking on a file, and choosing Properties.

How to do it...
Have a look at the following steps:
- Open
/config/site_post.php
in your code editor, or place this code, wherever it is appropriate in your own application. - Declare the ID of the file to load and be sure to set this to something relevant for your system:
$fileId = 17;
- Load the file:
$file = File::getByID($fileId);
- Dump the contents of the file variable:
my_debug($file);
How it works...
concrete5 will use this function to load the relevant file from the database, based on the numeric ID that you passed in. The static getByID
function will return a fully loaded file
object that you can work further with.
- Android Jetpack開發:原理解析與應用實戰
- Mastering RabbitMQ
- Apache Spark 2 for Beginners
- Blockly創意趣味編程
- Learn Scala Programming
- ADI DSP應用技術集錦
- 人人都懂設計模式:從生活中領悟設計模式(Python實現)
- 編程與類型系統
- Mastering Web Application Development with AngularJS
- Emotional Intelligence for IT Professionals
- Delphi開發典型模塊大全(修訂版)
- Mastering OAuth 2.0
- MySQL數據庫應用實戰教程(慕課版)
- Java編程指南:語法基礎、面向對象、函數式編程與項目實戰
- 微信公眾平臺開發最佳實踐