Jump to content

downloading files from mysql database


joebudden

Recommended Posts

hi,       
  i am writing a script enabling users to upload files to a mysql database

  so far my application enables users to:

login
logout
upload files
display uploaded files
delete uploaded files
modify file names

What i want to do now is allow the user to view the files in the browser ie jpgs word documents etc

this is what iv done so far ..

<?php
//connection to mySql
$con = mysql_connect("localhost","root","")or die ("Error: " . mysql_error());
//database matchdb is selected
mysql_select_db("p03293858db",$con)or die ("Error: " . mysql_error());

$selectfrmdb = "select filename,type,size,content "."from artefact where artefactId='".$_GET['id']."'";

$result = mysql_query($selectfrmdb,$con)or die('Error, query failed');

list($filename,$type,$size,$content) = mysql_fetch_array($result);

echo '<img src="$content"></img>';

mysql_close($con);
exit;
?>

any ideas ????

Link to comment
https://forums.phpfreaks.com/topic/31260-downloading-files-from-mysql-database/
Share on other sites

is your current code working??  if so, the download would be simple.  just make a hidden form field with the same variable $content as it's value and then make a submit button on each page.  Then just make code on your page to check for that submit button's press, grab the value of the hidden form field and then look up force file download tutorial on how to push the file to the user.

example

[code]if ($_POST['download']) { #if that's the name of the button you choose
  if ($_POST['hidden_content']) {
      #input code for pushing file to user
  }
}

<input type=\"hidden\" name=\"hidden_content\" value=\"$content\"> [/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.