これは、クライアントがリンクをクリックすると、Cで書かれたCGIプログラムの一部である、私は、ファイルが提示されるデフォルトのファイル名を指定して、ダウンロードを開始します。コンテンツ処理ファイル名 "suggestion"は常に無視されます。どうして?
私は仕様が明確にContent-dispositionヘッダで指定したファイル名が単に示唆されたと述べている知っているが、それは関係なく、私が使用しているブラウザ思わない、それは常に無視されます。私はその行動を私が間違っていることを意味すると解釈します。ここで
は私の問題を再現ストリップダウンコードスニペットです。例えばtest.cgiにコンパイルすると、プログラムは動作しますが、ブラウザーは "archive.tar.gz"ではなく "test.cgi"というファイル名でデータを保存します。
(ファイルI/Oエラーチェックと、この明確かつ簡潔に保つために除去他の安全なビット。)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#define CHUNK_SIZE 1024
int main(int argc, char *argv[]) {
int fd;
long bytes_remaining, bytes_to_get, bytes_read, bytes_sent, retval;
int chunksize;
unsigned char data_buffer[CHUNK_SIZE];
char header_str[200];
fd = open("archive.tar.gz", O_RDONLY);
if(fd == -1) {
printf("Content-type: text/html\n\n");
printf("Unable to open file: %s.<br><br>\n", strerror(errno));
return 0;
}
bytes_remaining = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
snprintf(header_str, 200, "Content-Type: application/x-compressed\r\n\r\nContent-Disposition: attachment; filename=\"archive.tar.gz\"\r\n\r\n");
write(1, header_str, strlen(header_str));
while(bytes_remaining > 0) {
if(bytes_remaining > CHUNK_SIZE) bytes_to_get = CHUNK_SIZE;
else bytes_to_get = bytes_remaining;
bytes_read = read(fd, data_buffer, bytes_to_get);
bytes_sent = write(1, data_buffer, bytes_read);
bytes_remaining -= bytes_sent;
}
close(fd);
return 0;
}
はなぜ私の提案のファイル名が一貫して無視されますか?
ありがとうございます。
CGIで値を受け取っていますか? [mcve]を提供し、[ask]を参照してください。 – Olaf
実際のアプリケーションでは、ダウンロードするファイルは要求されたURLのパラメータによって決まります。上記は最小限の完全で検証可能な例です。それをコンパイルし、サーバー上に置く、whatever_you_compiled_it_to.cgiを要求し、その代わりに、ブラウザのファイルをダウンロードし、それはそれはwhatever_you_compiled_it_to.cgiとして保存されますarchive.tar.gz命名。 – pgg
いいえ、そうではありません。コールがありません。それを呼び出す結果となるウェブサイトあなたは私が尋ねたものにも答えなかった。 – Olaf