Tripal
Functions
Files

Functions

 tripal_create_files_dir ($module_name, $path=FALSE)
 
 tripal_get_files_dir ($module_name=FALSE)
 
 tripal_get_files_stream ($module_name=FALSE)
 
 tripal_format_bytes ($bytes, $precision=2)
 
 tripal_get_user_uploads ($uid, $allowed_types=[], $module='tripal')
 
 tripal_get_user_files_dir ($user)
 
 tripal_is_user_files_dir_writeable ($user)
 

Detailed Description

Provides an application programming interface (API) for managing files within the Tripal data directory structure.

Function Documentation

◆ tripal_create_files_dir()

tripal_create_files_dir (   $module_name,
  $path = FALSE 
)

Creates a directory for a module in the Drupal's public files directory.

Previously it was recommended that this function be called during installation of the module in the .install file. However this causes permission problems if the module is installed via drush with a user account that is not the same as the web user. Therefore, this function should not be called in a location accessible via a drush command. The tripal_get_files_dir() and tripal_get_files_stream() will automatically create the directory if it doesn't exist so there is little need to call this function directly.

Parameters
$module_namethe name of the module being installed
$pathOptional sub-path to create

◆ tripal_format_bytes()

tripal_format_bytes (   $bytes,
  $precision = 2 
)

Formats a size (in bytes) in human readable format.

Function taken from php.net

Parameters
$bytesThe size of the file in bytes
$precisionThe number of decimal places to use in the final number if needed
Returns
string A formatted string indicating the size of the file

◆ tripal_get_files_dir()

tripal_get_files_dir (   $module_name = FALSE)

Retrieves the Drupal relative directory for a Tripal module.

Each Tripal module has a unique data directory which was created using the tripal_create_files_dir function during installation. This function retrieves the directory path.

Parameters
$module_name(Optional) The name of the module.
Returns
The path within the Drupal installation where the data directory resides

◆ tripal_get_files_stream()

tripal_get_files_stream (   $module_name = FALSE)

Retrieves the Drupal stream (e.g. public://...) for a Tripal module.

Each Tripal module has a unique data directory which was created using the tripal_create_files_dir function during installation. This function retrieves the directory path.

Parameters
$module_name(Optional) The name of the module.
Returns
The path within the Drupal installation where the data directory resides

◆ tripal_get_user_files_dir()

tripal_get_user_files_dir (   $user)

Retrieves the URI for the dedicated directory for a user's files.

This directory is used by the file uploader and by data collections.

Parameters
$userA Drupal user object.
Returns
The URI of the directory.

◆ tripal_get_user_uploads()

tripal_get_user_uploads (   $uid,
  $allowed_types = [],
  $module = 'tripal' 
)

Retrieves the list of files uploaded by a user.

Parameters
$uidThe ID of the user whose files should be retrieved.
$allowed_typesA list of valid extensions to restrict the files to.
$moduleThe name of the module that is managing the file.
Returns
A list of file objects.

◆ tripal_is_user_files_dir_writeable()

tripal_is_user_files_dir_writeable (   $user)

Checks if the user's dedicated directory is accessible and writeable.

Parameters
$userA Drupal user object.
Returns
TRUE if the user's directory is writeable. FALSE otherwise.