RISE has one common set of functions for files. Use them in your plugin whenever you save, show, read or delete a file. Then your plugin works with every storage: the local files folder, Google Drive, or a storage plugin.
How a file is saved
A saved file is a small array. Most modules keep a list of them in a files column (serialized).
| Key | What it holds |
| file_name | The stored file name, with a unique prefix. |
| file_size | Size in bytes. |
| file_id | The file id on a remote storage. Empty for local files. |
| service_type | Empty for local files, google for Google Drive, or the name of a storage plugin. |
The folder is not saved in the array. You pass it to the functions, for example get_setting("timeline_file_path").
Functions to use
| Function | Use it to |
| move_files_from_temp_dir_to_permanent_dir($path, $related_to) | Save the files of a Dropzone form. Returns the serialized files list. |
| move_temp_file($file_name, $path, $related_to) | Save one uploaded file. |
| save_app_file_content($file_name, $content, $path, $related_to) | Save a file from a content string. |
| get_source_url_of_file($file, $path, $view_type) | Get the url of a file. Use "thumbnail" as view type for images. |
| get_file_preview_data($file, $path) | Get the url and the preview options for a file preview modal. |
| get_app_file_content($file, $path) | Read the content of a file. Returns false when it is not found. |
| delete_app_files($path, $files) | Delete files. |
| is_google_drive_file($file) | Check if a file is on Google Drive. |
| get_local_file_path($relative_path) | Get the full server path of a local file or folder. |
| get_local_file_url($relative_path) | Get the url of a local file, for files that are always local. |
Please do not build file paths with getcwd() and do not build file urls with base_url(). These may change in the future, for example when files are kept in a separate folder for each site.
Example
//save the uploaded files
$files = move_files_from_temp_dir_to_permanent_dir(get_setting("timeline_file_path"), "my_plugin");
//show the first image
$files = unserialize($files);
$file = get_array_value($files, 0);
echo "
";
//read the content
$content = get_app_file_content($file, get_setting("timeline_file_path"));
//delete the files
delete_app_files(get_setting("timeline_file_path"), $files);
Hooks for local files
These filters let a plugin change where local files are kept.
| Filter | What it changes |
| app_filter_local_file_path | The full server path of a local file. You get the path and an array with relative_path. |
| app_filter_local_file_url | The url of a local file. You get the url and an array with relative_path. |
| app_filter_convert_local_file_urls_to_paths | The html of a PDF after the local file urls are changed to file paths. |
Storage plugins still use the existing hooks: app_hook_upload_file_to_temp, app_filter_move_temp_file, app_filter_get_source_url_of_file, app_filter_get_file_content and app_hook_delete_app_file. Now app_filter_get_file_content is used everywhere RISE reads a file, not only for downloads.