hi every one i have create a table with name upload
id int notnull
name varchar notnull
type varchar notnull
size varchar notnull
content varchar not null
and my code is the follwing but instead of iamge it show garbage value
<form method="post" enctype="multipart/form-data" action="image.php">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<td>Name:</td><td><input name="username" type="text" size"20"></input></td>
<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
$name = $_POST['username'];
if($_POST['upload']){
if($name!=''){
$servername="localhost";
$username="root";
$conn= mysql_connect($servername,$username)or die(mysql_error());
mysql_select_db("test",$conn);
$sql = "Insert into upload(username) values('$name')";
$result=mysql_query($sql,$conn) or die(mysql_error());?>
<div class="message">you have sucessfully upload picture<br/></div>
<?php }
else $error="Name is missing please fill it";
}
?>
<?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'];
$name = $_POST['username'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include 'config.php';
//include 'library/opendb.php';
$query = "INSERT INTO upload (name,size, type, content ) ".
"VALUES ('$fileName','$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
//include 'library/closedb.php';
echo "<br>File $fileName uploaded<br>";
}
?>
<?php
$con=mysql_connect("localhost", "root", "");
mysql_select_db("test",$con);
$dn = mysql_query('select content from upload where id="'.$id.'" ');
if(mysql_num_rows($dn)>0)
{
$dnn = mysql_fetch_array($dn);
//We display the user datas
?>
<?php while($dnn = mysql_fetch_array($dn))
{?>
<table style="width:500px;">
<tr>
<td><?php
?></td>
<div class='center'><img src="<?php echo $dnn['content']; ?>" /></td></div>
</tr>
<?php
}
//We add a link to send a pm to the user
if(isset($_SESSION['username']))
{
?>
<?php
}
}
else
{
echo 'This user dont exists.';
}
?>
</body>
</html>