Link to home
Start Free TrialLog in
Avatar of Amin El-Zein
Amin El-Zein

asked on

donwload file script

hello,
I have an IIS server and I have some files hosted on it.
I want to make sure users can download these files with user name and password parameters given in the URL, for example:

http://files.mydoamin/list.txt?username:user?password:pwd

Open in new window


So I don't want anyone to get access to the file without including his information.
Any opensource or script can do that?
Thanks.
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

As long as the files are hosted on IIS they are public.

What you need to do is to implement an API.
The API will receive both parameters and you can do a simple file where you can have "username and password"
So every time you get a call

https://myweb.com?username:user1&password:pwd1 (works)
https://myweb.com?username:user1 (fail missing password)
https://myweb.com?password:pwd1 (fail missing username)
https://myweb.com (fail missing both username and pwd).

Check if the request has the username and password and also make sure that they're valid.
Once this is checked it can download the file.

https://stackoverflow.com/questions/10937524/how-should-i-pass-multiple-parameters-to-an-asp-net-web-api-get
Avatar of Amin El-Zein
Amin El-Zein

ASKER

how i can do it ?
Hi there I left you in the last comment the way to do it :)
https://stackoverflow.com/questions/10937524/how-should-i-pass-multiple-parameters-to-an-asp-net-web-api-get

here's a video
https://www.youtube.com/watch?v=AJWwQEXd4Yk (at least the english can be understandable) :)
is there any easy php script to do that ? or any open source script that can do it ?
thanks
Hi Amin,

I try to do an exmple of what you need to do:
<?php

if (isset($url)) {
    if (isset($_GET['username']) && isset($_GET['password'])){
        // if the log is correct
        echo '<form action="yourscript.php" method="post">
                        <input type="button" class="btn btn-default" onclick="window.location=\'file.txt\'" value="exportTXT">
                        </p>
              </form>';
    } else {
        // log fail... retry
        header('Location: index.php');
        exit();
    }
}
?>

Open in new window

Hope this will help you.
is it the full script ? or I have to make other pages ?
It's an exemple, to how you have to do this:

You have to implement with your code where I put the comment.
I am not a developer , I want your help to make my request work.
thanks.
ASKER CERTIFIED SOLUTION
Avatar of Nicolas Lecanu
Nicolas Lecanu
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial