Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
  3.  
  4. {
  5.  
  6. $fileName = $_FILES['userfile']['name'];
  7.  
  8. $tmpName = $_FILES['userfile']['tmp_name'];
  9.  
  10. $fileSize = $_FILES['userfile']['size'];
  11.  
  12. $fileType = $_FILES['userfile']['type'];
  13.  
  14. $fileType = (get_magic_quotes_gpc() == 0 ? mysql_real_escape_string(
  15. $_FILES['userfile']['type']) :
  16. mysql_real_escape_string(stripslashes($_FILES['userfile'])));
  17.  
  18. $fp = fopen($tmpName, 'r');
  19.  
  20. $content = fread($fp, filesize($tmpName));
  21.  
  22. $content = addslashes($content);
  23.  
  24. fclose($fp);
  25.  
  26. if(!get_magic_quotes_gpc())
  27.  
  28. {
  29.  
  30. $fileName = addslashes($fileName);
  31.  
  32. }
  33.  
  34. mysql_connect("localhost","*****","***");
  35.  
  36. mysql_select_db("****");
  37.  
  38. $query = "INSERT INTO wp3_cte (FileupName, size, type, content ) ".
  39.  
  40. "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
  41.  
  42. mysql_query($query) or die('Error, query failed');
  43.  
  44. echo "File $fileName uploaded";
  45.  
  46. }
  47.  
  48. ?>
  49. <form method="post" enctype="multipart/form-data">
  50. <table width="350" border="0" cellspacing="1" cellpadding="1">
  51. <tbody>
  52. <tr>
  53. <td width="246">
  54. <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
  55.  
  56. <input id="userfile" type="file" name="userfile" /></td>
  57. <td width="80"><input id="upload" type="submit" name="upload" value=" Upload " /></td>
  58. </tr>
  59. </tbody>
  60. </table>
  61. </form>
  62. <html>
  63. <head>
  64. <title>Download File From MySQL Database</title>
  65. <meta http-equiv="Content-Type" content="text/html;
  66. charset=iso-8859-1">
  67. </head>
  68. <body>
  69.  
  70.  
  71. <?php
  72. mysql_connect("localhost","**********","**********");
  73. mysql_select_db("**********");
  74. $query = "SELECT id, FileupName FROM wp3_cte";
  75. $result = mysql_query($query) or die('Error, query failed');
  76. if (mysql_num_rows($result) == 0) {
  77. echo "Database is empty <br>";
  78. } else {
  79. while (list($id, $name) = mysql_fetch_array($result)) {
  80. ?>
  81. <a href="download.php?id=<?php echo urlencode($id); ?>"
  82. ><?php echo urlencode($name); ?></a> <br>
  83. <?php
  84. }
  85. }
  86. mysql_close();
  87. ?>
  88. </body>
  89. </html>
  90. <?php
  91. if (isset($_GET['id'])) {
  92. mysql_connect("localhost","**********","**********");
  93. mysql_select_db("**********");
  94. $id = $_GET['id'];
  95. $query = "SELECT FileupName, type, size, content"FROM wp3_cte WHERE id = '$id'";
  96. $result = mysql_query($query) or die('Error, query failed');
  97. list($name, $type, $size, $content) = mysql_fetch_array($result);
  98. header("Content-length: $size");
  99. header("Content-type: $type");
  100. header("Content-Disposition: attachment; filename=$name");
  101. ob_clean();
  102. flush();
  103. echo $content;
  104. mysql_close();
  105. exit;
  106. }
  107. ?>
  108.  
  109.  
  110. The problem i am facing is in this peace of code:`download.php`.
  111.  
  112. Uploaded file is showing properly if i click on download file blank page.
  113.  
  114. can any one help me Thanks in advance!!!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement