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'

Monday, February 24, 2014

Delete operation in Drupal 7

The following function is used to delete file and file usage in Drupal 7.
file_data($file);

The following db function is used to delete a record from a table in Drupal 7.
db_delete('table')->condition('field', $value->execute();

The following drupal function is used to delete a node in Drupal 7.
node_delete($nid);
Multiple node delete: node_multiple_delete(array($nid1, $nid2));

The following drupal function is used to delete a user in Drupal 7.
user_delete($uid);
Multiple user delete: user_multiple_delete(array($uid1, $uid2));

The following drupal function is used to delete a content type in Drupal 7.
node_type_delete($type);

Friday, February 21, 2014

Use file_prepare_directory() instead of file_check_directory()

In Drupal 7, use file_prepare_directory() instead of file_check_directory() from Drupal 6.

Drupal 6 file_directory_path not exists in Drupal 7

Drupal 6 file_directory_path not exists in Drupal 7. Use variable_get('file_public_path', conf_path() . '/files'); instead of file_directory_path();

The following function is return file directory relative path:  drupal_realpath('public://')