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.
<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>
You're not actually inserting the image into the database there.
When you want to insert a file into the database then you need to open the file up, grab it's contents and then store the contents. You're trying to upload an empty variable.
Instead of just putting $_POST['image'] into the database you need to do something like this:
$fp = fopen($_FILES['image']['tmp_name'], 'r'); // Open the file from the temporary directory
$content = fread($fp, filesize($_FILES['image']['tmp_name'])); // Read it into a variable