Hi everyone,
I'm uploading a picture and text to a database then displaying it on a page. I have the picture uploading fine, but it is adding the text that is giving me problems. Also displaying it has me lost. Here is my code for uploading the data.
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td>
<textarea name="info" cols="100" rows="15" width="100" height="100"></textarea>
</td>
</tr>
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$con = mysql_connect("mysql","xxxxx","xxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("inventory", $con);
$query = "INSERT INTO main (info, name, size, type, content ) ".
"VALUES ('$fileName', '$fileInfo', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
echo "<br>File $fileName uploaded<br>";
}
?>
And here is my code for displaying the data.
<?php
$con = mysql_connect("mysql","xxxxx","xxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("inventory", $con);
$id = $_GET['ID'];
if(!isset($ID) || empty($ID)){
die(" ");
}else
{
$query = mysql_query("SELECT * FROM main");
$row = mysql_fetch_array($query);
$content = $row['content'];
header('Content-type: image/jpg');
echo $content;
}
?>
Thanks!