MySQL Forums
Forum List  »  PHP

images
Posted by: Ryan Chles
Date: April 10, 2006 06:01PM

Hello Folks,

I am trying to upload images to mysql database. and everything works except, I can seem to actually put the image in the data base. Does anyone know how to do this? Is it really possible to even store actual pictures in a database? Any help would be great. here is what my code looks like.

Code:
<?php
error_reporting(E_ALL);
include "open_db.inc";

if($_POST['action']=="upload"){
$binName = $_FILE['binFile']['name'];
$binTemp = $_FILE['binFile']['tmp_name'];
$binType = $_FILE['binFile']['type'];
$binSize = $_FILE['binFile']['size'];
$binErr = $_FILE['binFile']['error'];

if(isset($_FILES['binFile']['name'] && $_FILES['binFile']['name'] !="")
{
$data1 = fopen($binName, 'w+');
$Content = fread($data1,$binSize);
$Content = addslashes($Content);
$binName = addslashes($binName);
strDescription = addslashes($_POST['txtDesription']);

sql="INSERT INTO binary_data";
$sql .="(description,bin_data,filename,filesize,filetype)";
$sql .="VALUES
('$strDescription','$Content','$binName',$binSize','$binType');

$result = mysql_query($sql,$db);

echo"Thank you. The new files was succesfully added to our database.<br><br>";

echo "<a href='main.php'>Continue</a>";
}
else
{
print $binErr;
}
mysql_close();
}
else{
?>
<html><body>
<form method="post" action="add2.php" enctype="multipart/form-data">
<input type=hidden" name="MAX_FILE_SIZE" value="90000000">
<input type="hidden" name="action" value="upload">
<table border="1">
<tr>
<td>Description</td>
<td><textarea name=txtDescription" rows="10
cols="50"></textarea></td>
</tr>
<tr>
<td>File:</td>
<td><input type="file" name="binFile"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value=Upload"></td>
</tr>
</table>
</form>
</body>
</html>

<?php
}
?>

Options: ReplyQuote


Subject
Written By
Posted
images
April 10, 2006 06:01PM
April 11, 2006 03:24AM
April 11, 2006 03:30AM
April 11, 2006 03:03PM
April 12, 2006 04:35PM
April 13, 2006 04:45AM
April 13, 2006 01:53PM
April 13, 2006 06:59PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.