php - My script downloads the source of the page and not the actual file -


i've got problem downloading script.. made uploading script -> adds files in folder called uploads , inserts id, filename , link database.but can't find way download uploaded file. here's download script:

 <?php      include('config.php');      $dwquery = mysqli_query($db, "select id, filename files");       $id = intval($_get['id']);           while ($row = mysqli_fetch_array($dwquery)) {             echo '<a href="download.php?id='.$row['id'].'">'.$row['filename'].'</a><br />';         }         $download = mysqli_query($db, "select link files id=$id");         $link = mysqli_fetch_array($download);          if($id != '') {         header('content-disposition: attachment; filename='.$link[0]);         readfile($_server['document_root'] . '/project/' .$link[0]);         }      ?> 

when select file download downloads source code of page , not actual file.

edit: downloads source code of download.php + text / code inside file want download. gets echo:

echo '<a href="index.php"> index </a> / <a href="upload.php"> upload </a> / <a href="download.php"> download </a> / <a href="logout.php"> logout </a><br />'; 

and downloaded file is:

<a href="index.php"> index </a> / <a href="upload.php"> upload </a> / <a href="download.php"> download </a> / <a href="logout.php"> logout </a><br /><a href="download.php?id=6">test1.php</a><br /><a href="download.php?id=5">test2.txt</a><br />  , here's actual code of file 

your code reads this:

show list of files if download id provided:     show content of file 

it should read this:

if download id provided     show content of file else     show list of files 

it possible getting path of file wrong have no error checking on existence of file.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -