Chrizz93

Untitled

Apr 29th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <?php
  2. // block any attempt to the filesystem
  3. if (isset($_GET['file']) && basename($_GET['file']) == $_GET['file']) {
  4.     $filename = $_GET['file'];
  5. } else {
  6.     $filename = NULL;
  7. }
  8. // define error message
  9. $err = 'Filen kunne ikke findes';
  10. ?>
  11.  
  12. <?php
  13.  
  14. if (!$filename) {
  15. // if variable $filename is NULL or false display the message
  16.     echo $err;
  17. } else {
  18. // define the path to your download folder plus assign the file name
  19.     $path = '' . $filename;
  20. // check that file exists and is readable
  21.     if (file_exists($path) && is_readable($path)) {
  22. // get the file size and send the http headers
  23.         $size = filesize($path);
  24.         header('Content-Type: application/octet-stream');
  25.         header('Content-Length: ' . $size);
  26.         header('Content-Disposition: attachment; filename=' . $filename);
  27.         header('Content-Transfer-Encoding: binary');
  28. // open the file in binary read-only mode
  29. // display the error messages if the file can´t be opened
  30.         $file = @ fopen($path, 'rb');
  31.         if ($file) {
  32. // stream the file and exit the script when complete
  33.             fpassthru($file);
  34.             exit;
  35.         } else {
  36.             echo $err;
  37.         }
  38.     } else {
  39.         echo $err;
  40.     }
  41. }
  42. ?>
  43. <form action="filer/<?php echo $row['content']; ?>">
  44.             <p><input type="submit" value="Se Filen"></p>
  45.             <img src="filer/<?php echo $row['content']; ?>">
  46.         </form>
  47. <?php
  48. $sql_select = "SELECT * FROM upload";
  49.         $result=$conn->query($sql_select);
  50.        
  51. ?>
Add Comment
Please, Sign In to add comment