I've been pulling my hair out trying to get this to work. I don't want this form to submit empty to my databank when the page loads. This causes a break (the infamous RED X) in the image gallery display.
Can someone please please please help me figure out what is wrong with this code. For the life of me I can't find the reason!!!!!!!!! Thanks.
<?php include('header.php'); ?>
<?php include('../path/to my/Connections.php'); ?>
<span class="titleAdmin">Logo</span> image upload <br />
<?php
if(isset($_POST['submit'])) {
$uploaddir = '/path/to/myl/logos/';
$uploadfile = $uploaddir . basename($_FILES['field1']['name']);
if(move_uploaded_file($_FILES['field1']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "File upload FAILED!\n";
}
$im_file_name = $uploaddir . basename($_FILES['field1']['name']);
$image_attribs = getimagesize($im_file_name);
$im_old = imageCreateFromJpeg($im_file_name);
$th_max_width = 150;
$th_max_height = 100;
$ratio = ($width > $height) ? $th_max_width/$image_attribs[0] : $th_max_height/$image_attribs[1];
$th_width = $image_attribs[0] * $ratio;
$th_height = $image_attribs[1] * $ratio;
$im_new = imagecreatetruecolor($th_width,$th_height);
imageAntiAlias($im_new,true);
$th_file_name = $uploaddir .'thumb/' . $_FILES['field1']['name'];
imageCopyResampled($im_new,$im_old,0,0,0,0,$th_width,$th_height, $image_attribs[0], $image_attribs[1]);
imageJpeg($im_new,$th_file_name,90);
}
$query1 = "INSERT INTO items (catID, iteImage, iteThumb) VALUES (1,'{$_FILES['field1']['name']}', '{$_FILES['field1']['name']}')";
$result1 = @mysql_query($query1);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
<p>image:
<input name="field1" type="file" id="field1" />
<br />
<br />
<input name="catID" type="hidden" id="catID" value="1" />
<input name="submit" type="hidden" id="submit" value="upload">
<input name="max_file_size" type="hidden" value="256000">
<input type="submit" name="Submit" value="Upload image" />
</p>
</form>
<p> </p>
<p> </p>
<?php include('footer.php'); ?>