forgot to get mime type when downloading files

This commit is contained in:
Andrew Pamment 2018-02-17 08:42:27 +10:00
parent 5e2d6afe3b
commit 701a9be612

View File

@ -895,11 +895,29 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
if (conf.file_directories[file_dir]->display_on_web) {
// send file
filename = www_files_get_from_area(file_dir, file_sub, filen);
mime = NULL;
// get mimetype
for (i=strlen(filename);i>0;--i) {
if (filename[i] == '.') {
mime = www_get_mime_type(&filename[i+1]);
break;
}
if (filename[i] == '/') {
mime = www_get_mime_type(NULL);
break;
}
}
if (mime = NULL) {
mime = www_get_mime_type(NULL);
}
free(filen);
if (filename != NULL) {
if (stat(filename, &s) == 0 && S_ISREG(s.st_mode)) {
fno = open(filename, O_RDONLY);
if (fno != -1) {
response = MHD_create_response_from_fd(s.st_size, fno);
MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mime);
sprintf(buffer, "%ld", s.st_size);