Skip to main content

Image

Drupal File Operation

Submitted by system on
This post will illustrate various handy file operations available in Drupal Get Absolute Path of a file from URI : drupal_realpath() A URI in drupal looks like: private://donor_registration/somefile.csv for a private file Absolute Path: /srv/www/example.com/public_html/sites/default/private/files/donor_registration/somefile.csv <?php $absolute_path = drupal_realpath($uri); drupal_set_message(t("Realpath is: $absolute_path"), 'status', FALSE); ?> -- Sources: https://api.drupal.org/api/drupal/includes!file.inc/function/drupal_realpath/7

Programmatically Saving File

Submitted by amitsedai on
Get the filename URI path from the dir_name located under public files directory. Save data in the destination. If file exists with the name, replace Get the download link. <?php $dest = file_build_uri('dir_name/'.$filename); $file = file_save_data($data, $dest, FILE_EXISTS_REPLACE); $download_link = file_create_url($file->uri); ?>