When you first upload an image, it generally goes to a temperory folder, where you can then verify that it meets certain critera, then if it passes you can move it to your permanant location.
I've pasted below a primative image upload and processing script I made a long time ago. It allows a website member to upload a logo to be displayed in their account. The first half of the script handles the upload, checks to make sure it has passed several criteria such as file size, image type, and verifies that a logo was actually uploaded. If it passes that criteria, it copies from the temperory location to the permanant location, and deletes the temp. file. The second half of the script resamples the image down to a certain size, proportionally (which also might be useful to you, so I left it there). The bottom of the script is the form itself. I had designed it to run in a popup, then close automatically when it was done processing, so you will have to edit the referesh statements if you don't do that... or it'll close your windows before its done processing... but you can play with it anyway... might be helpful.
EDIT: Forgot to add... it'd probably be just as easy to just upload the image to your final location, and show it to the user... if they change their mind, it's simple to delete... might be easier than working with the temperory file.
<?php
include('global/dbconnect.php');
if ($HTTP_POST_VARS['submit']) {
if (!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'])) {
$error = "You did not upload a file!";
unlink($HTTP_POST_FILES['file']['tmp_name']);
// assign error message, remove uploaded file, redisplay form.
} else {
//a file was uploaded
$maxfilesize=99999999999999999999;
if ($HTTP_POST_FILES['file']['size'] > $maxfilesize) {
$error = "file is too large";
unlink($HTTP_POST_FILES['file']['tmp_name']);
// assign error message, remove uploaded file, redisplay form.
} else {
if ($HTTP_POST_FILES['file']['type'] != "image/jpeg" AND $HTTP_POST_FILES['file']['type'] != "image/png" AND $HTTP_POST_FILES['file']['type'] != "image/pjpeg") {
echo '<p align="center" class="content"><font color="#FFFFFF"><b>This file type is not allowed.</b></font></p>';
unlink($HTTP_POST_FILES['file']['tmp_name']);
// assign error message, remove uploaded file, redisplay form.
} else {
//File has passed all validation, copy it to the final destination and remove the temporary file:
copy($HTTP_POST_FILES['file']['tmp_name'],"userlogos/".$user_id."".$HTTP_POST_FILES['file']['name']);
print "File has been successfully uploaded!";
$query13 = "INSERT into logos values ('0', '".$user_id."', '".$name."', '".$URL."userlogos/tn_".$user_id."".$HTTP_POST_FILES['file']['name']."')";
$result13 = mysql_query($query13);
if (!$result13)
{
echo 'ERROR: Your account information did not update.';
exit;
}
$filename = $URL."userlogos/".$user_id."".$HTTP_POST_FILES['file']['name'];
$filename_new = str_replace("userlogos/", "userlogos/tn_", $filename);
//IAMGE PROCESSING SCRIPT BEGINNING +++++++++++++++
function createthumb($name,$filename,$new_w,$new_h){
$size = getimagesize($name);
global $gd2;
$system=explode(".",$name);
if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
$old_x = $size[0];
$old_y = $size[1];
if($old_x <= 180 && $old_y <= 220){
$thumb_w = $old_x;
$thumb_h = $old_y;
}else{
$imagesize_x = $size[0];
$imagesize_y = $size[1];
$thumbsize_x = 180;
$thumbsize_y = 220;
$thumb_w = round(($imagesize_x * $thumbsize_y)/$imagesize_y);
if ($thumb_w > $thumbsize_x)
{
$thumb_w = $thumbsize_x;
$thumb_h = round(($imagesize_y * $thumbsize_x)/$imagesize_x);
}else{
$thumb_h = $thumbsize_y;
}
}
// if ($gd2==""){
// $dst_img=ImageCreate($thumb_w,$thumb_h);
// imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
// }else{
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
// }
if (preg_match("/png/",$system[1])){
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
createthumb($filename,$filename_new,180,220);
unlink($filename);
echo'<html>
<head>
</head>
<body bgcolor="#FF6600" text="#FF6600" onLoad="opener.location=\'index.php?p=user_logo\';self.close()">
</body>
</html>';
}
}
}
}
?>
<html>
<head>
<title>Upload Logo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="global/styles.css" rel="stylesheet" type="text/css">
</head>
<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="content">
<tr>
<td>
<form action="<?php echo $PHP_SELF;?>" method="post" enctype="multipart/form-data">
<div align="center">
<p>Choose a file to upload:<br>
<input type="file" name="file" class="formobjects">
<br>
<input name="name" type="text" class="formobjects" id="name">
- Image Name
<input type="hidden" name="close" value="yes">
<br>
<input type="submit" name="submit" value="submit" class="formobjects">
</p>
<p>Please select a JPG or PNG logo. Once uploaded, this window will close automatically.<br>Click Submit only once. Upload time will vary depending on your connection speed.</p>
</div>
</form></td>
</tr>
</table>
</body>
</html>