I am trying to upload an image within a form to my database, the form contains various text fields and one file field. (for the image) I can get it to work if i direct the image to a seperate table in the database but not into the same tabe as the rest of the data. I also tried submitting an image reference into the data table from the image table so that I can link the records together, but this doesnt work either.
Any ideas on what the usual way to do this is, or if there is obvious error in my code -
Much appreciated.
My code is:
////////
to deal with the images
/////////
$photo = addslashes(fread(fopen($FILES['file']['tmp_name'], "r"), $FILES['file']['size']));
$query = sprintf("INSERT INTO images(Image, FileType) VALUES ('%s', '%s')", $photo, $_FILES['file']['type']);
///////////
workaround due to images going to another table
//////////
$query = "INSERT INTO details('ImageId') SELECT DISTINCT 'ImageId' FROM 'images'";
///////////
an extract of the form process script
///////////
<tr valign="baseline">
<td nowrap align="right">Other_information</td>
<td><input type="text" name="other_information" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Insert photo::</td>
<td><label for="file"></label>
<input type="file" name="file" id="file" />
<input type="hidden" name="MAX_FILE_SIZE" value="200000">
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>