Page 1 of 1

d/l a file in a secure way

Posted: Wed Jul 07, 2004 5:12 am
by pelegk2
i want to d/l a file
but i dont wantto let the user where the file on the server
and to prevent from him d/l file that he is not
authorized to d/l
how cna i do that?
i see in some places that when u press a link the file is bein redirected from another place,given a long string that tells which file to d/l but
the user can't take that link and byhimself to d/l that
thnaks in advance
peleg

Posted: Wed Jul 07, 2004 7:52 am
by feyd
create a download script that knows where it is, or how to find it. The download script passes the binary data of the file back to the browser. There are many threads here about forcing download.. check those out for details on how to write a download script. You can also read the [php_man]header[/php_man]() user comments and things..

Posted: Thu Jul 08, 2004 3:25 am
by pelegk2
ok thanks alot
and if i want find i message u:)

Posted: Sun Jul 11, 2004 12:17 pm
by pelegk2
feyd : i tried everything on that page and nothing worked:(

Posted: Sun Jul 11, 2004 12:22 pm
by feyd
you tried this kinda stuff?

Code: Select all

<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');

// The PDF source is in original.pdf
readfile('original.pdf');
?>
^ from [php_man]header[/php_man]() documentation...

Posted: Sun Jul 11, 2004 12:29 pm
by pelegk2
i tried to d/l a rar file and i get errors that file cant be opened

Posted: Sun Jul 11, 2004 12:32 pm
by feyd
post your code.

Posted: Sun Jul 11, 2004 12:35 pm
by pelegk2
well itried the pdf file an igot a file that the pdf cant open1

Posted: Sun Jul 11, 2004 12:35 pm
by pelegk2
thi is the code

Code: Select all

<?

// We'll be outputting a PDF
header('Content-type: application/pdf');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="Getting Started Guide.pdf"');

// The PDF source is in original.pdf
readfile('original.pdf');

?>

Posted: Sun Jul 11, 2004 12:46 pm
by feyd
you may need to urlencode() the filename...

Posted: Sun Jul 11, 2004 12:51 pm
by pelegk2
i know that
but the problem is with rar files for example
how do i d/l them?

Posted: Sun Jul 11, 2004 1:01 pm
by feyd

Code: Select all

<?php 
// We'll be outputting a PDF 
header('Content-type: application/x-rar-compressed'); 

// It will be called downloaded.pdf 
header('Content-Disposition: attachment; filename="downloaded.rar"'); 

// The PDF source is in original.pdf 
readfile('original.rar'); 
?>
should do it..

Posted: Sun Jul 11, 2004 1:42 pm
by pelegk2
where camn i find list of zall types like : x-rar-compressed

Posted: Sun Jul 11, 2004 1:47 pm
by feyd
google is where I found that mime-type.

Posted: Mon Jul 12, 2004 12:05 am
by pelegk2
10X:)