PHP Code:
<?php @require_once('../includes/connect.php'); ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Real Estate Professionals</title>
<link href="res.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td align="center"><table width="760" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="100" bgcolor="#00833D"> </td>
<td width="500" background="../images/bkgd_ltgray50x2000.jpg">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><span class="listing01"> <span class="body01"><strong><br>
</strong></span></span><span class="head01">UPLOAD RESIDENTIAL PICTURE</span>
<span class="listing01"><span class="body01"><strong><br>
</strong></span>< back to <a href="admin.php">admin</a> -
exit to <a href="../index.htm">website</a> ><br>
</span><br>
<img src="../images/spacer-grn.jpg" width="10" height="10">
<img src="../images/spacer-grn.jpg" width="10" height="10">
<img src="../images/spacer-grn.jpg" width="10" height="10"> </div>
</p></td>
</tr>
</table>
</td>
<td width="100" bgcolor="#393989"> </td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="10">
<tr align="left" valign="bottom">
<td width="100" bgcolor="#00833D"> </td>
<td width="500">
<?php
$resselect = @mysql_query("SELECT
res_street01,
res_city,
res_state,
res_zip,
res_price,
res_status,
res_type
FROM residential WHERE res_id='$id'");
if (!$resselect) {
echo("Error SELECTING data from database!<br><br>" .
"<br> />Error: " . mysql_error() . "</p>");
exit();
}
while ($resarray = mysql_fetch_array($resselect)) {
$resstreet01 = htmlspecialchars($resarray["res_street01"]);
$rescity = htmlspecialchars($resarray["res_city"]);
$resstate = htmlspecialchars($resarray["res_state"]);
$reszip = htmlspecialchars($resarray["res_zip"]);
$resstatus = htmlspecialchars($resarray["res_status"]);
$resprice = htmlspecialchars($resarray["res_price"]);
$restype = htmlspecialchars($resarray["res_type"]);
}
$imgselect = @mysql_query("SELECT
image_tmb_name,
image_tmb_path,
image_tmb_width,
image_tmb_height
FROM image WHERE image_res_id='$id'");
if (!$imgselect) {
echo("Error SELECTING data from database!<br><br>" .
"<br> />Error: " . mysql_error() . "</p>");
exit();
}
while ($resarray2 = mysql_fetch_array($imgselect)) {
$imagetmbname = htmlspecialchars($imgarray["image_tmb_name"]);
$imagetmbpath = htmlspecialchars($imgarray["image_tmb_path"]);
$imagetmbwidth = htmlspecialchars($imgarray["image_tmb_width"]);
$imagetmbheight = htmlspecialchars($imgarray["image_tmb_height"]);
}
?>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="250" align="right" valign="top">
<table width="220" border="0" align="right" cellpadding="0" cellspacing="10">
<tr>
<td align="left" valign="top"><hr align="left" width="180" size="1" noshade>
<span class="caption_cap">Record Id <?php echo $id; ?></span><br>
<span class="listing01"><strong><?php echo $restype ;?></strong><br>
<?php echo $resstreet01 ;?><br>
<?php echo $rescity ;?>
<?php echo $resstate ;?> <?php echo $reszip ;?><br>
<br>
<?php echo $resstatus ;?><br>
<?php echo $resprice ;?></span>
<hr align="left" width="180" size="1" noshade>
<br><span class="listing01">Use the <b>BROWSE</b> button below to select an
PICTURE to be uploaded to your website.<br>
<br>
Only <b>JPG</b>, <b>GIF</b>, and <b>PNG</b>
PICTURES under 1.7 MB in file size can be uploaded.</span><br>
</td>
</tr>
</table>
</td>
<td width="250" align="left" valign="top">
<table width="250" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="125" align="left" valign="top"><span class="caption_cap">PICTURE 01<br>
<img src="../images/arrow-down.gif" width="9" height="9">
<span class="listing01">[<strong>DELETE</strong>]</span><br>
</span></td>
<td width="125" align="left" valign="top"><span class="caption_cap">PICTURE 02<br>
</span></td>
</tr>
<tr>
<td align="left" valign="top"><img src="../<?php echo $imagetmbpath ;?><?php echo $imagetmbname ;?>"
width="<?php echo $imagetmbwidth ;?>" height="<?php echo $imagetmbheight ;?>" border="1"><br></td>
<td align="left" valign="top"><img src="../images/tmb-spacer-gry90.jpg" width="90" height="90" border="1"></td>
</tr>
<tr>
<td align="left" valign="middle"> </td>
<td align="left" valign="middle"> </td>
</tr>
<tr>
<td align="left" valign="top"><span class="caption_cap">PICTURE 03<br>
<br>
</span></td>
<td align="left" valign="top"><span class="caption_cap">PICTURE 04<br>
</span></td>
</tr>
<tr>
<td align="left" valign="top"><img src="../images/tmb-spacer-gry90.jpg" width="90" height="90" border="1"></td>
<td align="left" valign="top"><img src="../images/tmb-spacer-gry90.jpg" width="90" height="90" border="1"></td>
</tr>
</table>
</td>
</tr>
</table>
<blockquote>
<?php
//load the config file
include("../includes/images-config.php");
//if the for has submittedd
if (isset($_POST['uploadimage'])){
$file_type = $_FILES['imgfile']['type'];
$file_name = $_FILES['imgfile']['name'];
$file_size = $_FILES['imgfile']['size'];
$file_tmp = $_FILES['imgfile']['tmp_name'];
//check if you have selected a file.
if(!is_uploaded_file($file_tmp)){
echo "<br><br><span class='listing01'>Either the PICTURE you tried to upload <br>
exceeds the 1.7 megabyte size limit, <br><br>or <br><br>
you did not select an PICTURE to upload!
<br><br><br><a href=\"$_SERVER[PHP_SELF]\">back</a></span><br><br><br><br>";
exit(); //exit the script and don't do anything else.
}
//check file extension
$ext = strrchr($file_name,'.');
$ext = strtolower($ext);
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
echo "<br><br><br><span class='listing01'>You tried to submit a invalid file type; <br>
(only gif, jpg, png, and jpeg IMAGES are allowed).<br><br><br>
<a href=\"$_SERVER[PHP_SELF]\">back</a></span><br><br><br><br>";
exit(); //exit the script and don't do anything else.
}
//get the file extension.
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
//create a random file name
$rand_name = md5(time());
$rand_name = rand(0,999999999);
// RESIDENTIAL THUMBNAIL ------------------------------------------------------------
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$tmb_new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/jpeg" || $file_type == "image/jpg"){
$tmb_new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$tmb_new_img = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$tmb_new_img = imagecreatefromgif($file_tmp);
}
//get the new width variable.
$tmbwidth = $img_residential_tmb_width;
//list width and height and keep height ratio.
list($width, $height) = getimagesize($file_tmp);
$imgratio=$width/$height;
if ($imgratio>1){
$newtmbwidth = $tmbwidth;
$newtmbheight = $tmbwidth/$imgratio;
}else{
$newtmbheight = $tmbwidth;
$newtmbwidth = $tmbwidth*$imgratio;
}
//function for resize image.
if (function_exists(imagecreatetruecolor)){
$tmb_resized_img = imagecreatetruecolor($newtmbwidth,$newtmbheight);
}else{
die("Error: Please make sure you have GD library ver 2+");
}
imagecopyResampled($tmb_resized_img, $tmb_new_img, 0, 0, 0, 0, $newtmbwidth, $newtmbheight, $width, $height);
// explode it to get the extention
$parts = explode(".", $rand_name);
$tmb_name = 'tmb-'.$parts[0].$parts[1];
//save image
ImageJpeg ($tmb_resized_img,"../$path_residential_tmbs/$tmb_name.$file_ext");
ImageDestroy ($tmb_resized_img);
ImageDestroy ($tmb_new_img);
}
// RESIDENTIAL IMAGE ------------------------------------------------------------
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$pic_new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/jpeg" || $file_type == "image/jpg"){
$pic_new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$pic_new_img = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$pic_new_img = imagecreatefromgif($file_tmp);
}
//get the new width variable.
$picwidth = $img_residential_pic_width;
//list width and height and keep height ratio.
list($width, $height) = getimagesize($file_tmp);
$imgratio=$width/$height;
if ($imgratio>1){
$newpicwidth = $picwidth;
$newpicheight = $picwidth/$imgratio;
}else{
$newpicheight = $picwidth;
$newpicwidth = $picwidth*$imgratio;
}
//function for resize image.
if (function_exists(imagecreatetruecolor)){
$pic_resized_img = imagecreatetruecolor($newpicwidth,$newpicheight);
}else{
die("Error: Please make sure you have GD library ver 2+");
}
imagecopyResampled($pic_resized_img, $pic_new_img, 0, 0, 0, 0, $newpicwidth, $newpicheight, $width, $height);
// explode it to get the extention
$parts = explode(".", $rand_name);
$pic_name = 'pic-'.$parts[0].$parts[1];
//save image
ImageJpeg ($pic_resized_img,"../$path_residential_pics/$pic_name.$file_ext");
ImageDestroy ($pic_resized_img);
ImageDestroy ($pic_new_img);
}
$sqlinsert = "INSERT INTO image SET
image_res_id='$id',
image_pic_name='$pic_name.$file_ext',
image_pic_path='$path_residential_pics',
image_pic_width='$newpicwidth',
image_pic_height='$newpicheight',
image_tmb_name='$tmb_name.$file_ext',
image_tmb_path='$path_residential_tmbs',
image_tmb_width='$newtmbwidth',
image_tmb_height='$newtmbheight'";
if (@!mysql_query($sqlinsert)) {
echo("<p>Error INSERTING data to database: " . mysql_error() . "</p>\n</body>\n</html>");
exit();
}
echo "<div align='center'><br><br><br>Residential IMAGE uploaded!</div><br><br><br>";
}else{
echo "<span class='listing01'>
Then click the <strong>SAVE</strong> button to send a PICTURE to your website
(the upload process may take a few minutes, pleaae wait).<br><br><br>";
echo "<script>
function view_img(img_name){
document[img_name].src = uploadimage.imgfile.value;
document[img_name].width = 150;
}
</script>
<form action='$_SERVER[PHP_SELF]' method='post'
name='uploadimage' enctype='multipart/form-data'>
<input name='id' type='hidden' value='$id' /> //edited to show source of error and correct value
// was <input name='id' type='hidden' value='<?php echo $id ?>' />
<input type='hidden' name='MAX_FILE_SIZE' value='1700000'>
<span class='caption_cap'>Select Picture:</span><br>
<input type='file' name='imgfile' size='45' class='body01'
onchange=\"javascript:view_img('img_vv');\"><br>
<br>
<div align='center'><input type='submit' name='uploadimage' value=' SAVE '>
<br><br><br>
<img src='' name='img_vv' width='0'></div>
</form>"; }
?>
</blockquote>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"> <span class="body01">
<img src="../images/spacer-grn.jpg" width="10" height="10">
<img src="../images/spacer-grn.jpg" width="10" height="10">
<img src="../images/spacer-grn.jpg" width="10" height="10"> <br>
<br>
<?php @require_once('../includes/copyright.php'); ?>
</span><br>
<br>
</div></td>
</tr>
</table></td>
</tr>
</table>
</td>
<td width="100" bgcolor="#393989"> </td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
</body>
</html>
<?php mysql_close() ?>
Bookmarks