easyphp - PHP corrupted file -


this page click on download button.

this things found online did not work

why downloaded file alwayes damaged or corrupted?

force downloading pdf file, corrupt file

$query = "select id, name docu"; $result = mysqli_query($con,$query) or die('error, query failed');  if(mysqli_num_rows($result)==0){     echo "database empty <br>"; } else{     while ( (list($id, $name) = mysqli_fetch_array($result, mysqli_both))){ ?> <p><a href="download.php?id=<?= $id ?>">name : <?= $name ?></a></p> 

this download code. when download file, corrupted.

if(isset($_get['id'])){  $id    = $_get['id'];   $con = mysqli_connect("localhost:3306", "waduser", "waduser", "fyp"); if(!$con) {   die("cannot connect: " . mysqli_error());  }  mysqli_select_db($con,"fyp");   $query = "select * docu id ='" .$id ."'";  $result = mysqli_query($con,$query) or die('error, query failed');  if($row =  $result ->  fetch_array(mysqli_assoc))  {     $name = $row['name'];     $type = $row['type'];     $content = $row['content']; //content of file     $size = $row['size']; //file size     header('content-type:"' . $type . '"');     header('content-length:' . $size  .'');     header('content-disposition: attachment; filename="' .$name. '"');    }   } ?> 

i think jim trying have sent headers have not sent file itself.

so try

$name = $row['name']; $type = $row['type']; $content = $row['content']; //content of file $size = $row['size']; //file size header('content-type:"' . $type . '"'); header('content-length:' . $size  .''); header('content-disposition: attachment; filename="' .$name. '"'); echo $content; 

also think safer remove spaces around short_tag usage @ least in href property.

<p><a href="download.php?id=<?=$id?>">name : <?= $name ?></a></p> 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -