包括php sql代码中的缩略图上传

I have an upload to mysql script in php that works perfectly for a property website - inserting all relevant fields and the main image.

The problem is however, this image is used in a slideshow which identifies the thumbnail as xxxxxt.png where the main image is xxxxx.png for example.

My php code is:

<?php include 'dbc.php'; page_protect();

if(!checkAdmin()) {header("Location: login.php");
exit();
}

$host  = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$login_path = @ereg_replace('admin','',dirname($_SERVER['PHP_SELF']));
$path   = rtrim($login_path, '/\\');

foreach($_GET as $key => $value) {
    $get[$key] = filter($value);
}

foreach($_POST as $key => $value) {
    $post[$key] = filter($value);
}   

$uniqid = md5(uniqid(mt_rand()));

?>


<?php 
if($_FILES['photo']) //check if we uploading a file
{
    $target = "images/properties/"; 
    $target = $target . basename( $_FILES['photo']['name']);


    $title = mysql_real_escape_string($_POST['title']); 
    $desc = mysql_real_escape_string($_POST['desc']); 
    $extra = mysql_real_escape_string($_POST['extra']); 
    $postcode = mysql_real_escape_string($_POST['postcode']); 
    $price = mysql_real_escape_string($_POST['price']);  
    $pandp = mysql_real_escape_string($_POST['pandp']);  
    $pic = "images/properties/" .(mysql_real_escape_string($_FILES['photo']['name']));
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{
    mysql_query("INSERT INTO `furnishings` (`title`, `postcode`, `desc`, `extra`, `productcode`, `price`, `status`, `pandp`, `photo`) VALUES ('$title', '$postcode', '$desc', '$extra', '" . $uniqid . "', '$price', 'tolet.png', '$pandp', '$pic' )") ;     

    echo "The property has been added to the lettings portfolio"; 
} 
else 
{ 
    echo "Error uploading new property - please ensure all the fields are correctly entered and the file is an image"; 

}
} 
?> 

The html code for the upload form is:

<form enctype="multipart/form-data" action="addlet.php" method="POST">
  <table width="600px" border="2" cellpadding="5"class="myaccount">
   <tr>
       <td width="135">Title: </td>
       <td width="427"><input name="title" type="text" size="40"/></td>
    </tr>
     <tr>
       <td>Description: </td>
       <td><textarea name = "desc" rows="3" cols="40"></textarea></td>
     </tr>
          <tr>
       <td>Property Features: </td>
       <td><textarea name = "extra" rows="3" cols="40"></textarea></td>
     </tr>
          <tr>
       <td>Postcode: </td>
       <td><input name = "postcode" type="text" size="40" /></td>
     </tr>
     <tr>
       <td>Price per week (&pound;): </td>
       <td><input name = "price" type="text" size="40" /></td>
     </tr>
        <tr>
       <td>Furnished/Unfurnished: </td>
       <td><input name = "pandp" type="text" size="40" /></td>
     </tr>
     <tr>
       <td>Main Image: </td>
       <td><input type="file" name="photo" class="forms" /></td>
     </tr>  </table></p>
<p> <input type="submit" class="CMSbutton" value="Add" /></p>
</form>

Is there a simple way to add an extra line of code which will insert two images into the desired target on the server, (images/properties/) - one the original name of the image, and one the thumbnail version (with a "t" on the end of the image name).

As they are both reasonably small I am not fussed about resizing the thumbnail as the code is pretty much done I dont want to have to rebuild everything!

Any help much appreciated

Thanks JD

If your image file is being moved into place successfully, I would take this strategy: create columns is_uploaded, is_thumb_created and is_image_created in your database table. Upon successful upload and move, set the first one.

Then run a cron or other background system that generates a 'main' and a 'thumb' view from the uploaded image (bearing in mind that the uploaded image may be way too large for an ordinary screen-size picture). Upon the successful generation of these images, the relevant columns can be set as 'done', and the row remains non-live until this happens.

This approach is a great deal more scalable, incidentally, since it is not clogging up your web request with expensive image processing.