Hello,
I am currently able to upload an image and the info is being inserted into the db correctly.
I would like to add a gd function to add 3 image re-sizes into it.
locations and sizes
/prop_enlarged/ max 600px 400px
/prop_listing/ max 405px 270px
/prop_thumb/ max 135px 90px
I would love any help,
Matthew
<?php include('headera.php'); ?>
<?php
$propid = $_SESSION['propid'];
// define constant which contains the maximum file size in bytes
define('MAX_FILE_SIZE', 4000000);
if (array_key_exists('btn', $_POST)) {
// define new constant which contains the path the the upload folder
define('UPL_FLD','uploads/');
//Find the extension
$flext = pathinfo($_FILES['frmfile']['name']);
$ext = strtolower($flext['extension']);
// create new file name
$file = str_replace(' ', '_', $_POST['frmname'].'.'.$ext);
$file = strtolower($file);
// create variable and assign the formatted value of MAX_FILE_SIZE to it
$maxfs = number_format(MAX_FILE_SIZE/1024, 1).'KB';
$fsize = false;
// check the file size
if ($_FILES['frmfile']['size'] > 0 && $_FILES['frmfile']['size'] <= MAX_FILE_SIZE) {
$fsize = true;
}
// allow MIME file types
$filetype = array('image/gif','image/jpeg','image/pjpeg','image/png');
$ftype = false;
// check if uploaded file type is allowed
foreach($filetype as $type) {
if ($type == $_FILES['frmfile']['type']) {
$ftype = true;
break;
}
}
if ($ftype && $fsize && $_POST['frmname'] != '') {
switch($_FILES['frmfile']['error']) {
case 0:
// move file to the upload folder
$upload = move_uploaded_file($_FILES['frmfile']['tmp_name'],UPL_FLD.$file);
if ($upload) {
$msg = $_FILES['frmfile']['name'].' uploaded successfully';
$img_name = $file;
$query = "SELECT `propid` FROM `images` WHERE `propid` = $propid";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
$sql = "INSERT into images (propid,userid,img_name,mainImage) VALUES ('$propid','$userid','$img_name','N')";
$result = mysql_db_query($dbname, $sql) or die("Failed Query of " . $sql); //do the query
} else {
$sql = "INSERT into images (propid,userid,img_name,mainImage) VALUES ('$propid','$userid','$img_name','Y')";
$result = mysql_db_query($dbname, $sql) or die("Failed Query of " . $sql); //do the query
}
} else {
$msg = 'Error.<br />Please try again.';
}
break;
case 3:
$msg = 'Error.<br />Please try again.';
break;
default:
$msg = 'Error - please contact administrator';
}
} elseif ($_FILES['frmfile']['error'] == 4) {
$msg = 'Please select file';
} elseif ($_POST['frmname'] == '') {
$msg = 'Please provide your full name';
} else {
$msg = $_FILES['frmfile']['name'].' cannot be uploaded.<br />';
if(!$ftype) {
$msg .= 'Acceptable file formats are: .gif, .jpg, .png<br />';
}
if(!$fsize) {
$msg .= 'Maximum file size is '.$maxfs;
}
}
}
?>
<div id="memberblock">
<div id="memberleft">
<?php include('control_panel_tools.php'); ?>
</div>
<div id="memberright">
<h1>Upload Images</h1>
<?php if(isset($msg)) { echo '<p class="warning">'.$msg.'</p>'; } ?>
<form action="" method="post" enctype="multipart/form-data" name="frm_upload" id="frm_upload">
<input type="hidden" name="frmname" value="<?php echo date("YmdHis") ?>" id="frmname" />
<input type="hidden" name="propid" value="<?=$propid?>" />
<label >File:</label>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />
<input name="frmfile" type="file" id="frmfile" size="30" />
<input type="submit" name="btn" id="btn" value="Upload" />
</form>
<?php echo $userid; ?>
</div>
<?php include('footera.php'); ?>