I don't get the download to work. I googled a lot but I don't see my fault, anybody does???
So what I did:
A csv file is created and stored in: $uri = "public://tmp".'/'.$filename;
For the moment this is: /sites/default/files/tmp/.
The file exists in the db.file_managed table and also a web-accessible URL for a stream to an external or local file.:
$file_object = file_save_data($data, $uri, FILE_EXISTS_RENAME);
$url = file_create_url($file_object->uri);
The file exists, it's all on my localhost so the permissions are:
(duke is my name on my pc, every folder has chmod -R 775)
- drwxrwxr-x 8 duke www-data 4096 Sep 10 19:59 files
- drwxrwxr-x 4 duke www-data 4096 Sep 10 20:42 tmp
A generated file has the following, e.g.:
-rw-rw-r-- 1 www-data www-data 5 Sep 9 22:27 adress_list_2015_09_09_22_27_11.csv
So I think that the Apache could read/write the file!???
I made a download link like this,
$options_download['attributes']['download'] = $filename;
// We need query-params for download-token here.
$dl_link = l(t('Download'), $url, $options_download);
... and set it in drupal_set_message():
drupal_set_message(
t('!download',array('!download'=>$dl_link))
);
If I click on the link, I get the following text (translated from German):
File not found: Files under .../sites/default/files/tmp/adress_list_2015_09_10_21_10_10.csv could not be found.
If I refresh the site in browser I get:
You don't have permission to access /musik/sites/default/files/tmp/adress_list_2015_09_10_21_10_10.csv on this server. And I'm admin here!???
So does anybody knows what I'm doing wrong? As i stated: this is public file...
Thx in advance,
maen
Comments
I at least need to see the
I at least need to see the chunks of code in context. Note placing files in tmp is not a good practice. And from what you are showing you seem to be missing some code for managing the file.
my code:
Without the creation of the content of data(Firstname etc. ...) this is my complete code:
The issue with tmp I will solve later. So which code do I miss????
The tmp file will not allow
The tmp file will not allow downloads for security reasons. Try saving to a different directory