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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -