- concrete5 Cookbook
- David Strack
- 262字
- 2021-08-13 16:16:03
Getting a file's path
Once you have loaded the file
object, there are a multitude of different methods that you can call, to get all of the different attributes associated with that file. One of the most common and important attributes is that file's path.
Getting ready
In this recipe, we will get a file's path and use it to display an image stored in the file manager.
Once again, we will be referencing an image with the ID of 1
. Be sure to adapt the code in this recipe to load an image that actually exists in your concrete5 installation.
How to do it...
Have a look at the following steps:
- Open
/config/site_post.php
in your editor. - Declare the ID of the file to be loaded:
$fileId = 1;
- Load the file by its ID:
$file = File::getByID($fileId);
- Get the file's path:
$path = $file->getRelativePath();
- Output the path to the screen:
echo $path; exit;
How it works...
The file manager stores files in various locations through the concrete5 website, typically beneath the files/
folder, which gets broken up into a few machine-readable folders consisting of integers. Since these paths are too hard to figure out and predict on a regular basis, the file object API allows us to get those paths with a simple function call.
There's more...
You will need the actual absolute path of a file, if you are working with the image in PHP's fopen
function, for instance. For that, you will use the getPath
function:
$fullPath = $file->getPath();
See also
- The Loading a file by its ID recipe
- Unity Virtual Reality Projects
- 我的第一本算法書
- Rust Cookbook
- MATLAB for Machine Learning
- Mastering Git
- 細(xì)說(shuō)Python編程:從入門到科學(xué)計(jì)算
- Troubleshooting Citrix XenApp?
- Arduino可穿戴設(shè)備開(kāi)發(fā)
- Serverless Web Applications with React and Firebase
- Elasticsearch Essentials
- PHP與MySQL權(quán)威指南
- MySQL 8從零開(kāi)始學(xué)(視頻教學(xué)版)
- Drupal 8 Development:Beginner's Guide(Second Edition)
- Learning ECMAScript 6
- Python數(shù)據(jù)可視化之matplotlib實(shí)踐