Can anyone point out/help as to why my script is not working for uploading an image to a directory and the name of the image to the database. At the moment once I submit the form, it goes to the script page but remains blank, i look in the database and nothing has happened...I have used a similar script on another one of my sites and it has worked but I have adjusted it slightly to this one.
Here is the form
<form action="uploadimage.php" method="post" enctype="multipart/form-data" >
<input type="file" name="image" />
<br />
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<br />
<input type="submit" id="submit" value="Upload">
</form>
and here is my uploadimage.php script
<?php
include "include/conn.php";
include "include/session.php";
?>
<?php
// Check to see if the type of file uploaded is a valid image type
function is_valid_type($file)
{
$valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif");
if (in_array($file['type'], $valid_types))
return 1;
return 0;
}
function showContents($array)
{
echo "<pre>";
print_r($array);
echo "</pre>";
}
$TARGET_PATH = "images/";
// Get POSTed variables
$image = $_FILES['image'];
$image['name'] = mysql_real_escape_string($image['name']);
$TARGET_PATH .= $image['name'];
// Make sure all the fields from the form have inputs
if ($image['name'] == "" )
{
$_SESSION['error'] = "All fields are required";
header("Location: addvox.php");
exit;
}
// Verify file is an image
if (!is_valid_type($image))
{
$_SESSION['error'] = "You must upload a jpeg, gif, or bmp";
header("Location: addvox.php");
exit;
}
// move file into the directory and the path name into the database
if (move_uploaded_file($image['tmp_name'], $TARGET_PATH))
{
$sql = "INSERT INTO images(image) VALUES ({$image['name']}) ";
$result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
header("Location: addvox.php");
exit;
}
else
{
$_SESSION['error'] = "Could not upload file. Check read/write persmissions on the directory";
exit;
}
?>
It seems to upload the image to the directory, but nothing is getting through to the database, it just remains empty