Note that there are some explanatory texts on larger screens.

plurals
  1. PODownload files from MYSQL database
    primarykey
    data
    text
    <p>ok i got files uploading to my database alright. but having problems downloading files from the database, it shows as a link and when i click on the link nothing happens.</p> <p>im still new to php so my code my not be perfect. </p> <p>here is my upload file</p> <pre><code> &lt;?php require 'connect.php'; ?&gt; &lt;form method="post" enctype="multipart/form-data"&gt; &lt;table width="350" border="0" cellpadding="1" cellspacing="1" class="box"&gt; &lt;tr&gt; &lt;td width="246"&gt; &lt;input type="hidden" name="MAX_FILE_SIZE" value="2000000"&gt; &lt;input name="userfile" type="file" id="userfile"&gt; &lt;/td&gt; &lt;td width="80"&gt;&lt;input name="upload" type="submit" class="box" id="upload" value=" &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;?php if(isset($_POST['upload']) &amp;&amp; $_FILES['userfile']['size'] &gt; 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileType = $_FILES['userfile']['type']; $fileSize = $_FILES['userfile']['size']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $query = "INSERT INTO upload (name, type, size, content) ". "VALUES ('$fileName', '$fileType', '$fileSize', '$content')"; mysql_query($query) or die('Error, query failed'); echo "&lt;br&gt;File $fileName uploaded&lt;br&gt;"; } ?&gt; Here is my download &lt;?php require 'connect.php'; $query = "SELECT id, name FROM upload"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "Database is empty &lt;br&gt;"; } else { while(list($id, $name) = mysql_fetch_array($result)) { ?&gt; &lt;a href="download.php?id=&lt;?php echo urlencode($id);?&gt;"&gt;&lt;?php echo urlencode($name);? &gt;&lt;/a&gt; &lt;br&gt; &lt;?php } } exit; mysql_close() ?&gt; &lt;?php require 'connect.php'; $query = "SELECT id, name FROM upload"; if(isset($_GET['id'])) { $id = $_GET['id']; $query = "SELECT name, type, size, content " . "FROM upload WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); $content = $row['content']; header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-type: $type"); header("Content-length: $size"); exit; print $content; ob_clean(); flush(); echo $content; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload