here is the script
<?php
include("db.php");
$bbuserinfo['userid'] = "1";
//This is the resize/sampler.
function resample($img, $max_w, $max_h, $type, $thumb)
{
switch ($type) {
case 2:
// get original images width and height
list($or_w, $or_h, $or_t) = getimagesize($img);
// obtain the image's ratio
$ratio = ($or_h / $or_w);
// original image
$or_image = imagecreatefromjpeg($img);
// resize image?
if ($or_w > $max_w || $or_h > $max_h) {
// resize by height, then width (height dominant)
if ($max_h < $max_w)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// resize by width, then height (width dominant)
if ($max_w < $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
//Resize by neither (as it is equal anyways)
if ($max_w == $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// copy old image to new image
$rs_image = @imagecreatetruecolor($rs_w, $rs_h);
@imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
}
// image requires no resizing
else {
$rs_w = $or_w;
$rs_h = $or_h;
$rs_image = $or_image;
}
if($thumb == true)
{
$image = explode('/',$img);
$x = 0;
$num_dir = count($image)-1;
while($x < count($image)-1)
{
$pre_img .=$image[$x]."/";
$x++;
}
$img = $pre_img."/sml_".$image[count($image)-1];
$img;
}
// generate resized image
imagejpeg($rs_image, $img, 100);
return true;
break;
case 3:
// get original images width and height
list($or_w, $or_h, $or_t) = getimagesize($img);
// obtain the image's ratio
$ratio = ($or_h / $or_w);
// original image
$or_image = imagecreatefrompng($img);
// resize image?
if ($or_w > $max_w || $or_h > $max_h) {
// resize by height, then width (height dominant)
if ($max_h < $max_w)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// resize by width, then height (width dominant)
if ($max_w < $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
//Resize by neither (as it is equal anyways)
if ($max_w == $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// copy old image to new image
$rs_image = imagecreatetruecolor($rs_w, $rs_h);
imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
}
// image requires no resizing
else {
$rs_w = $or_w;
$rs_h = $or_h;
$rs_image = $or_image;
}
if($thumb == true)
{
$image = explode('/',$img);
$img = $image[(count($image)-1)]."sml_".$image[count($image)];
print $img;
}
// generate resized image
imagepng($rs_image, $img, 100);
return true;
break;
case 4:
// get original images width and height
list($or_w, $or_h, $or_t) = getimagesize($img);
// obtain the image's ratio
$ratio = ($or_h / $or_w);
// original image
$or_image = imagecreatefromgif($img);
// resize image?
if ($or_w > $max_w || $or_h > $max_h) {
// resize by height, then width (height dominant)
if ($max_h < $max_w)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// resize by width, then height (width dominant)
if ($max_w < $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
//Resize by neither (as it is equal anyways)
if ($max_w == $max_h)
{
if ($or_h < $or_w)
{
$rs_w = $max_w;
$rs_h = $rs_w * $ratio;
}
else
{
$rs_h = $max_h;
$rs_w = $rs_h / $ratio;
}
}
// copy old image to new image
$rs_image = imagecreatetruecolor($rs_w, $rs_h);
imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
}
// image requires no resizing
else {
$rs_w = $or_w;
$rs_h = $or_h;
$rs_image = $or_image;
}
// generate resized image
if($thumb == true)
{
$image = explode('/',$img);
$img = $image[(count($image)-1)]."sml_".$image[count($image)];
print $img;
}
imagegif($rs_image, $img, 100);
return true;
break;
}
}
?>
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<?php $headinclude;?>
<title><?php $vboptions['bbtitle'];?></title>
</head>
<body>
<br /><br /><br /><br />
<center>
<?php
$bbuserinfo['userid'] = "1";
if($bbuserinfo['userid'] != NULL)
{}
else
{
$url = 'connexion.php'; $timeout = 0;
header('Refresh: ' . $timeout . ';url=' . $url);
print'
<meta http-equiv="refresh" content="'.$timeout.';url='.$url.';">
<script type="text/javascript">
setTimeout(function(){window.location.replace("'.$url.'; ", '.($timeout * 0).');
</script>';
}
if($bbuserinfo['userid'])
{
print'
<form action="'.$_server['php-self'].'" method="post"
enctype="multipart/form-data" id="something" class="uniForm">
';
// @include("imgbands.php"); //
print'
<br /><hr />
<table>
<tr>
<td>
Uploader la photo (#1):
</td>
<td>
<input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
</td>
</tr>
<tr>
<td>
Description (optionel):
</td>
<td>
<INPUT TYPE="TEXT" NAME="infos" VALUE="" size="60">
</td>
</tr>
</table>
<INPUT TYPE="hidden" NAME="user" VALUE="'.$bbuserinfo['username'].'" size="60">
<input name="submit" type="submit" class="submitButton" value="AJOUTER L\'IMAGE" />
</form>
';
}
$band = $_POST['band'];
if($_POST['submit'])
{
$imagenamz = $_FILES['new_image']['name'];
$originalname = $_FILES['new_image']['name'];
$date = date('dmy');
$imagename = "$band" . "_" . $date . "_" . $originalname;
echo $imagename;
$vraidate = date('d/m/y');
$nom = $_POST['user'];
$infos = $_POST['infos'];
echo "<br />L'image a été ajouté dans l'album photos de <b>$band</b><hr><br />";
$source = $_FILES['new_image']['tmp_name'];
$target = "db/img/images/".$imagename;
move_uploaded_file($source, $target);
$imagepath = $imagename;
$save = "db/img/images/" . $imagepath; //This is the new fileyou saving
$file = "db/img/images/" . $imagepath; //This is the originalfile
list($width, $height, $att) = getimagesize($file) ;
$size = getimagesize($file);
$uploadx = $size[0];
$uploady = $size[1];
}
list($width, $height, $type, $attr) = getimagesize($target);
resample($target, 800, 800, $type, false);
resample($target, 150, 150, $type, true);
if(isset($_POST['submit'])){
// if file exists
// add to database
$filename = 'db/img/images/sml_".$imagepath."';
if (file_exists($filename)) {
$band = $_POST['band'];
$originalname = $_FILES['new_image']['name'];
$date = date('dmy');
$imagename = "$band" . "_" . $date . "_" . $originalname;
// echo $imagename;
$vraidate = date('d/m/y');
$nom = $_POST['user'];
$infos = $_POST['infos'];
$result = mysql_query("INSERT INTO bands_pics (id,band,url,date,infos,valide,user) VALUES ('NULL', '$band', '$imagename','$vraidate','$infos','0','$nom')");
}
}
?>