Hi, I am trying to upload a single image but I keep getting an error that is at the bottom that tells me the upload failed -
Its really annoying & I have been going round in circles for days now -
here is my php
<?
//Include database connection details
require_once('includes/config.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link)
{
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db)
{
die("Unable to select database");
}
//if submit button has been submiied to form
if(isset($_POST['submit']))
{
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$image = $_FILES['profile_image']['name'];
$datetime = date('l jS F Y h:i:s'); //create date time
//Image Size Validations
if(($_FILES["profile_image"]["size"] / 1024)>1024){
$errmsg_arr[]='Image should not be greater than 1(MB) 1024kb.';
$errflag=true;
}
// Image validation
if($image == '')
{
$errmsg_arr[] = 'Select a picture to upload to your gallery.';
$errflag = true;
}
else // Image file type validation
{
$arr = explode('.', $image);
$ext = strtolower($arr[1]);
if($ext != "jpg" && $ext != "jpeg" && $ext != "png" && $ext != "gif")
{
$errmsg_arr[] = 'Profile image must be in JPG/JPEG/PNG/GIF format.';
$errflag = true;
}
}
if($errflag == false)
{
//Create INSERT query & insert to image gallery
$qry = "INSERT INTO mgallery(id,gimg,title) VALUES('','$image_name','$title')";
$result = @mysql_query($qry);
}
else
{
die("UPLOAD failed");
}
}
?>
and the form to go with the above code is this
<table width="500" align="center">
<tr>
<td width="500" valign="top"><table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#A6D2FF"><img name="addpictures" src="http://www.website.com/members/images/Pictures128.png" width="64" height="64" hspace="5" vspace="5" align="middle" border="0" title="Add more pictures to your profile" alt="addpictures"><font face='Verdana, Arial, Helvetica, sans-serif' size='2' color='#2a4c79'>Upload new pictures to your online image gallery</font></td>
</tr>
<tr>
<td align="center"><?php
if(count($errmsg_arr) > 0)
{
echo '<ul class="err">';
foreach($errmsg_arr as $msg)
{
echo '<li>',$msg,'</li>';
}
echo '</ul>';
unset($errmsg_arr);
}
?><form id="imgupload" name="imgupload" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<table width="500" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<th><div align="left">Upload Image to Gallery</div></th>
<td><input name="profile_image" class="tb10" type="file" id="profile_image" title="browse for a new image to upload" size="35" /></td>
</tr>
<tr>
<th><div align="left">Picture Comments</div></th>
<td><textarea name="title2" id="title2" cols="35" rows="2" title="Add comments to your picture upload"></textarea></td>
</tr>
<tr>
<td><div align="left"></div></td>
<td><input type="submit" class="tb10" name="submit" value="Upload new image" /></td>
</tr>
</table>
</form></td>
</tr>
</table>
</td>
</tr>
</table>
Im hoping someone can point me in the right direction as to where I am going wrong
cheers