D
D
Dmitry2015-07-09 14:19:39
PHP
Dmitry, 2015-07-09 14:19:39

How to download a file from a web server using a direct link in PHP?

Available:
OS - Windows
Web server - IIS 7
DB MySql
Links to files are written to the DB, like - D:\dir\one_more_dir\files\file.txt
The files are on the D:\ drive, IIS is on the C:\ drive.
Script:

$res = mysql_query("SELECT link FROM files");
$row = mysql_fetch_array($res);
do {
print "<a href='index.php?file=".$row['link']."'>Download</a></td>";
}
while($row = mysql_fetch_array($res));

if (isset($_GET['file'])) {
$file = $_GET['file'];

if (file_exists($file)) {
print "OK";
}
}

It breaks off here - if (file_exists($file))
The value in the file variable comes like this, for example - D:\dir\one_more_dir\files\file.txt
IUSR gave the user rights to the directory, the option of connecting a virtual folder to IIS is not suitable .
Can you please tell me what can be done in this situation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RadialAdmin, 2015-07-09
@Purge

Try the same thing from the IIS folder, then from the C: drive folder, then from other places. Most likely something with the rights (IIS can work as LocalServices) or with the passed path itself.

S
Sergey Zelensky, 2015-07-09
@SergeyZelensky-Rostov

I think the best solution is to keep the files on the server, because as far as I remember, php can't do that

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question