...

View Full Version : my image upload php script won't work plz help



adams2887
04-03-2011, 07:41 PM
hi i am trying to upload an image but it doesn't work :( I have been trying for ages but without any luck. I was wondering if anyone would be kindly enough to take a look at it :)

Basicly i'm getting my echo error message "problem uploading image" displayed constantly, even before i try upload it keeps saying it. It is also not uploading.
my database
id (int5) auto_increment
image_name (varchar100)
image (blob)

Here is my code i have two php files.


//addproduct.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="600" height="382" border="3" BORDERCOLOR="#CD3788" bgcolor="#FFFFFF" align="center" cellpadding="0" cellspacing="2">
<tr>
<form action="addproduct.php" method="post" enctype="multipart/form-data">
<td>
<table width="100%" border="0" BORDERCOLOR="#CD3788" cellpadding="3" cellspacing="1">
<tr>
<td colspan="3"><strong>Add Product</strong></td>
</tr>

<tr>
<td><font color="black">Add Image</font></td>
<td>:</td>
<td><input type="file" name="image" id="image" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Add">
</td>
</tr>
</table>
</td>

</form>
</tr>
</table>

<?php
// connect to host and database
include('config.php') or die(mysql_error());

// file properties
$file = $_FILES['image']['tmp_name'];

if (!isset ($file))
echo "Please select an image";
else
{
$image = addslashes (file_get_contents ($_FILES['image'] ['tmp_name']));
$image_name = addslashes ($_FILES['image'] ['image_name']);
$image_size = getimagesize ($_FILES['image'] ['tmp_name']);

if ($image_size==false)
echo "Thats not an image";
else
{
if (!$insert = mysql_query ("INSERT INTO products VALUES ('','$image_name','$image')"))
echo "Problem uploading image.";
else
{
$lastid = mysql_insert_id ();
echo "Image uploaded. <p />Your image:<p /><img src=get.php?id=$lastid>";
}
}

}
?>
</body>
</html>

//get.php

<?php
include('config.php') or die(mysql_error());

$id = addslashes($_REQUEST['id']);

$image = mysql_query("SELECT * FROM products WHERE id=$id");
$image = mysql_fetch_assoc ($image) ;
$image = $image ['image'];

header ("Content-type: image/jpeg");

echo $image;
?>

please help.
thankyou for your time :)

mlseim
04-03-2011, 08:53 PM
Separate the HTML form from the script.
Make them two different files. That will
help you a lot with troubleshooting your
problem.


.

poyzn
04-04-2011, 12:06 PM
post here config.php file listing. I think that the problem is in mysql connection.
the result of including config.php is true so your script will never die with mysql connection error.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum