richclever
IS-IT--Management
Hi,
This is probably a really simple question but I can't figure out where I am going wrong.
I want to upload images from a form that also has other info in it but I can't get the images to upload.
My form html is as follows.
My php in insert.php is as follows
As far as I'm concerned, the information should be written to the database (as indeed it is) and the file should be written to the directory (the file name is the id number in the database which is auto incrementing)
I know that php is et up correctly - I can upload using other ready made scripts no problems; but I can't get this to work.
Any ideas??
Thanks
Rich
This is probably a really simple question but I can't figure out where I am going wrong.
I want to upload images from a form that also has other info in it but I can't get the images to upload.
My form html is as follows.
Code:
<form enctype="multipart/form-data" form action="insert.php" method="POST" >
<table width="100%" border="1" bordercolor="#99CCFF">
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif">Name</font></td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif">Age</font></td>
<td><input name="age" type="text" id="age"></td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif">Description</font></td>
<td><textarea name="description" id="description"></textarea></td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif">Upload image</font></td>
<input type ="hidden" name = "MAX_FILE_SIZE" value ="30000">
<td><input name="imagefile" type="file" id="imagefile"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit"></td>
<td> </td>
</tr>
</table>
</form>
My php in insert.php is as follows
Code:
<?
require ('../conf.php');
$query="INSERT INTO catinfo ( name, age, description) VALUES ( '$name', '$age', '$description' )";
$result = @mysql_query($query);
$uid= mysql_insert_id();
$filename = $uid . '.jpg';
$add = "..\images\$filename";
if (move_uploaded_file($_FILES['imagefile']['tmp_name'], $add)) {
echo "file uploaded";
}else{echo "Failed to upload file Contact Site admin to fix the problem";
}
?>
As far as I'm concerned, the information should be written to the database (as indeed it is) and the file should be written to the directory (the file name is the id number in the database which is auto incrementing)
I know that php is et up correctly - I can upload using other ready made scripts no problems; but I can't get this to work.
Any ideas??
Thanks
Rich