Monday, March 17, 2014

Get the file size in Drupal

The following function is used to return the file size,

$file = file_load($fid)
echo filesize(drupal_realpath($file->uri));

url - it will return the file public url (public://filname.ext)
file_create_url() - it will return there relative url of the file (http://localhost/sites/default/files/filname.ext)
drupal_realpath() - it will return the absolute url of the file path.(sites/default/files/filename.ext)



Thursday, March 13, 2014

Find the text or value in MYSQL table using REGEXP

We can use REGEXP command to find the string value in MYSQL table.
SELECT * FROM <table> WHERE <column> REGEXP '<string>';

Ex: SELECT * FROM watchdog WHERE message REGEXP 'message'