
March 31st, 2004, 05:51 PM
|
 |
Cast down
|
|
Join Date: Jul 2003
Location: Sweden
Posts: 321
Time spent in forums: 5 h 56 m 35 sec
Reputation Power: 6
|
|
|
Anti-Leech CGI C script, Is this okay? How do I set default file name?
This will eventually be used for audio files when it's done. I do not want people to link to audio files on a site.
Right now it works (I am trying it with image files) but is there anything seriously wrong with it? I mean is there a way for the user to get the path to the file?
Code:
#include <stdio.h>
int main(void) {
FILE *fp;
int i;
long len;
/* First check where the user came from ... etc */
/* Check id to see what file the user
requested and send it back to the
client */
fp=fopen("abc.jpeg", "rb");
if (0==fp) {
fprintf(stderr, "Error opening file!\n");
return 1;
}
fseek(fp, 0, SEEK_END);
len=ftell(fp);
/* printf("Filesize: %ld\n", len); */
rewind(fp);
printf("Content-type:image/jpeg\xC\xA\n");
for (i=0; i<len; ++i)
putchar(fgetc(fp));
fclose(fp);
return 0;
}
Two things: where would I store the files so that the program can read them but not the user? I *can* put them in a hard-to-guess named dir but is there a real fix?
and if possible, how do I set the default download name? So if the user does right click > save target as.. it displays the correct filename.
Last edited by movEAX_444 : March 31st, 2004 at 06:28 PM.
|