File & Image Storage

The Db_File class represents a link to the file system stored in the database. Usually you need to work with this class when you want to store files and images. The link created is maintained so if the object is deleted, the linked file is also deleted.

Parent class: Db_ActiveRecord

Class fields

  • $name – a file name
  • $size – size of a file, in bytes $description - a file description

Class methods

$file->get_thumb_path($width, $height, $as_jpeg = true)

creates an image thumbnail and returns its relative URL. The $width and $height parameters could be either integer numbers or the ‘auto’ word. If you specify an integer number for the width or height, the thumbnail will have the exact width or height value, in pixels. Use the ‘auto’ word to scale an image dimension proportionally. For example, to generate a thumbnail with fixed width of 100 pixels and proportional height, use the following code:

$url = $file->get_thumb_path(100, 'auto');

The last parameter allows you to generate PNG images with transparency support. By default the parameter value is TRUE and the method generates a JPEG image. Pass the FALSE value to the parameter to generate a PNG image.


returns TRUE is the file is an image. The function returns TRUE for files with the following extensions: jpeg, jpg, gif, png.