How to create a link to a file in a module? In Drupal 7 I have a custom module that create a file in public://company/my.csv but in my module admin interface I want to create link to this file in a status message :

drupal_set_message('download your ' . l('file', $url));


To link the file I tried

$url = file_create_url('public://company/my.csv');
$url = drupal_get_path('file', 'my.csv');


I tried also to make myself the link to sites/default/files etc but it doesn't run. Sometimes I get 404 not found and sometimes "You cannot access to this directory".

(I have already checked that the file is well created in the good folder)

Any help is appreciated.
file_create_url() is right choice. Check the url it generates and try to open it directly in browser. If it fails do one of these:


Check if file is exists in right folder
If yes, check if it readable (filesystem permissions). Also check permissions for files/ directory.
If file exists and is readable, check your server setup. It should allow to view files from files/ directory. Probably you have wrong mod_rewrite config (apache) or wrong nginx config.