image upload to mysql
Posted: Mon Jun 08, 2009 4:49 pm
I am trying to upload images to a mysql database via a php form. All of the data uploads...except the image file which stays at 0kb in the db. My code is as follows: Any help? I am pretty sure it is some silly little thing.
The add image form:
The insert script:
the attached image shows what happens when submitting:
The add image form:
Code: Select all
<h1>Upload a New Image</h1>
<p>To add a new image, simply fill in the form below and click on the "Upload Image" button located at the bottom of this page. To upload additional images for the property, simply repeat the process for each image.</p>
<p>
<form class="mid" action="insert_img.php" method="post" onsubmit="this.submit(); this.reset(); return false" enctype="multipart/form-data">
<strong>MLS Number: (REQUIRED!)</strong> <input type="text" name="mls" size="30"><br><br>
<strong>IMAGE:</strong> <input name="image" type="file"><br><br>
<strong>Thumbnail?:</strong>
<SELECT NAME="tn">
<OPTION>N</OPTION>
<OPTION>Y</OPTION>
</SELECT><br><br>
<strong>Alt Text:</strong> <input type="text" name="alt" size="30"><br><br>
<strong>Image Title:</strong> <input type="text" name="title" size="60"><br><br>
<br><input type="Submit" value="Upload Image"> <input type="reset" value="clear form">
</form>
</p>Code: Select all
<?
$username="hotspot3_hotspot";
$password="[redacted]";
$database="hotspot3_properties";
$mls=$_POST['mls'];
$tn=$_POST['tn'];
$alt=$_POST['alt'];
$title=$_POST['title'];
$image=$_POST['image'];
$path = $_FILES['image']['tmp_name'];
$name = $_FILES['image']['name'];
$size = $_FILES['image']['size'];
$type = $_FILES['image']['type'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO images VALUES ('{}','{$mls}','{$tn}','{$alt}','{$title}','{$name}','{$size}','{$type}','{$image}')";
mysql_query($query);
mysql_close();
?>
<script language="javascript">
location.replace("admin.php?page=addimage2");
</script>