This is what I tried.
First I took the autoincrement away from my id column in table_images. Both id columns are set as primary.
This is my submit.php file which uploads the image
[php]<?php ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?>
<?php
include 'connect.php';
// upload the file
if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) {
// file needs to be jpg,gif,bmp,x-png and 4 MB max
if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") && ($_FILES["image_upload_box"]["size"] < 8000000))
{
// some settings
$max_upload_width = 500;
$max_upload_height = 500;
$thumb_height = 150;
// if uploaded image was JPG/JPEG
if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){
$image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]);
}
// if uploaded image was GIF
if($_FILES["image_upload_box"]["type"] == "image/gif"){
$image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]);
}
// BMP doesn't seem to be supported so remove it form above image type test (reject bmps)
// if uploaded image was BMP
if($_FILES["image_upload_box"]["type"] == "image/bmp"){
$image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]);
}
// if uploaded image was PNG
if($_FILES["image_upload_box"]["type"] == "image/x-png"){
$image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]);
}
$remote_file = "image_files/".$_FILES["image_upload_box"]["name"];
$thumb_file = "thumbs/".$_FILES["image_upload_box"]["name"];
imagejpeg($image_source,$remote_file,100);
chmod($remote_file,0644);
//Save image as thumb
// get width and height of original image
list($image_width, $image_height) = getimagesize($remote_file);
if($image_width>$thumb_width || $image_height >$thumb_height)
{
$proportions = $image_width/$image_height;
$new_height = $thumb_height;
$new_width = round($thumb_height*$proportions);
$thumb_image = imagecreatetruecolor($new_width , $new_height);
$image_source = imagecreatefromjpeg($thumb_file);
imagecopyresampled($thumb_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($thumb_image,$thumb_file,100);
imagedestroy($thumb_image);
//add the files pathname to the database table image_thumbs
$uploaded = $thumb_file;
$aname = $_POST['aname'];
$query = mysql_query("INSERT INTO image_thumbs VALUE('id', '$uploaded', '$aname')");
$query2 = mysql_query("SELECT `id` FROM `image_thumbs` WHERE `imagepath` LIKE '$uploaded'");
}
// get width and height of original image
//if landscape make width 500, if portrait make height 500
list($image_width, $image_height) = getimagesize($remote_file);
if($image_width>$max_upload_width || $image_height >$max_upload_height)
{
$proportions = $image_width/$image_height;
if($image_width>$image_height)
{
$new_width = $max_upload_width;
$new_height = round($max_upload_width/$proportions);
}
else
{
$new_height = $max_upload_height;
$new_width = round($max_upload_height*$proportions);
}
$new_image = imagecreatetruecolor($new_width , $new_height);
$image_source = imagecreatefromjpeg($remote_file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image,$remote_file,100);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image,$thumb_file,100);
//add the files pathname to the database table table_images.;,
$uploaded = $remote_file;
$query = mysql_query("INSERT INTO table_images VALUE(NULL, '$query2')");
}
imagedestroy($image_source);
header("Location: submit.php?upload_message=image uploaded&upload_message_type=success&show_image=".$_FILES["image_upload_box"]["name"]);
exit;
}
else{
header("Location: submit.php?upload_message=make sure the file is jpg, gif or png and that is smaller than 4MB&upload_message_type=error");
exit;
}
}
?>
Image Upload with resize
body,td,th {
font-family: Arial, Helvetica, sans-serif;
color: #111111;
font-size: 12px;
}
.upload_message_success {
padding:4px;
background-color:#000000;
border:1px solid #006600;
color:#FFFFFF;
margin-top:10px;
margin-bottom:10px;
}
.upload_message_error {
padding:4px;
background-color:#CE0000;
border:1px solid #990000;
color:#FFFFFF;
margin-top:10px;
margin-bottom:10px;
}
Submit an image
<?php if(isset($_REQUEST['upload_message'])){?>
<div class="upload_message_<?php echo $_REQUEST['upload_message_type'];?>">
<?php echo htmlentities($_REQUEST['upload_message']);?>
</div>
<?php }?>
Image file, maximum 4MB. it can be jpg, gif, png:
Description
<br />
<br />
<br />
<?php if(isset($_REQUEST['show_image']) and $_REQUEST['show_image']!=''){?>
Uploaded Image:
![]()
<?php }?>
[/php]
I added this line to the code that adds the data to image_thumbs
[php]$query2 = mysql_query(“SELECT id
FROM image_thumbs
WHERE imagepath
LIKE ‘$uploaded’”);[/php]
I also change the code to add the data to table images
[php]$query = mysql_query(“INSERT INTO table_images VALUE(NULL, ‘$query2’)”);[/php]
This is my show.php file
[php]
Gallery
body{
background-color:yellow;
}
#thumbs{
width: 1300px;
position: relative;
top: 40px;
left: 0px;
}
#here{
position: relative;
left:100px;
background-color:white;
}
div.thumb{
float: left;
padding: 10px 5px 10px 5px;
margin-bottom: 60px;
}
img.thumbnail{
border-style: solid;
border-width: 2px;
border-color: red;
background-color: black;
padding: 15px;
}
<?php
include 'connect.php';
?>
Here are all the images in the gallery:
<?php
$q = "SELECT a.thumbpath AS thumbpath, b.imagepath AS imagepath
FROM tumbs AS a
JOIN images AS b
USING(id)";
if($r = mysql_query($q))
{
echo ‘
’;
while($row=mysql_fetch_array($r))
{
echo ‘
’,
“
![Image]()
”,
‘
’;
}
echo '</div>';
}
else
{
echo mysql_error();
}
?>
[/php]
The data is being added to image_thumbs but not to table_images.
Nothing is showing up in the gallery at all when I run show.php.
Thanks for looking!
Glen