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.
HTMLPHPScripting Languages

Avatar of undefined
Last Comment
Nicolas Lecanu

8/22/2022 - Mon
Jose Gabriel Ortega Castro

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
Amin El-Zein

ASKER
how i can do it ?
Jose Gabriel Ortega Castro

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) :)
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Amin El-Zein

ASKER
is there any easy php script to do that ? or any open source script that can do it ?
thanks
Nicolas Lecanu

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.
Amin El-Zein

ASKER
is it the full script ? or I have to make other pages ?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Nicolas Lecanu

It's an exemple, to how you have to do this:

You have to implement with your code where I put the comment.
Amin El-Zein

ASKER
I am not a developer , I want your help to make my request work.
thanks.
ASKER CERTIFIED SOLUTION
Nicolas Lecanu

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.