//error_reporting(0);
?>
if (!isset($_COOKIE["id"]) || $_COOKIE['usertype']!="chatmodels" )
{
header("location: ../../login_sender.php");
} else{
include("../../dbase.php");
$result=mysql_query("SELECT user from $_COOKIE[usertype] WHERE id='$_COOKIE[id]' LIMIT 1");
while($row = mysql_fetch_array($result))
{ $username=$row['user']; }
}
mysql_free_result($result);
$errorMsg="";
//function that handles creation of thumbnails
function LoadJpeg ($imgname,$tocreate) {
$tnsize="80";//thumbnail size
$bigimage = @ImageCreateFromJPEG ($imgname); // Attempt to open
if (!$bigimage){
$result=false;
echo "Das Bild konnte nicht hochgeladen werden. Bitte versuche es noch einmal
In der Regel mußt du das Bild nur folgenden Maßen anpassen Auflösung ca. 800 x 800 Pixel und 100kb.
! $endstr ";
//exit();
}
$tnimage = ImageCreate($tnsize,$tnsize);
$white = ImageColorAllocate ($tnimage,0, 0, 0);
$sz = GetImageSize($imgname);
// load our internal variables
$x = $sz[0]; // big image width
$y = $sz[1]; // big image height
// find the larger dimension
if ($x>$y) { // if it is the width then
$dx = 0; // the left side of the new image
$w = $tnsize; // the width of the new image
$h = ($y / $x) * $tnsize; // the height of the new image
$dy = ($tnsize - $h) / 2; // the top of the new image
}else{ // if the height is larger then
$dy = 0; // the top of the new image
$h = $tnsize; // the height of the new image
$w = ($x / $y) * $tnsize; // the width of the new image
$dx = ($tnsize - $w) / 2; // the left edgeof the new image
}
// copy the resized version into the thumbnal image
ImageCopyResized($tnimage, $bigimage, $dx, $dy, 0, 0, $w, $h, $x, $y);
//if we manage to create the thumbnail
if (ImageJPEG($tnimage,$tocreate,80) && $x<1000 && $y<1000){
$result=true;
} else{ //if we dont
$result=false;
if ($x>1000 || $y>1000){
$errorMsg="Bild zu groß. Maximale Größe ist 800x800 Pixel und 100kb.";
} else{
$errorMsg="Bild konnte nicht hochgeladen werden. Bitte versuche es noch einmal.";
}
//exit();
}
return $result;
}
if(!isset($_COOKIE["id"]))
{
header("Location: ../../login_sender.php");
} else if (isset($_FILES['ImageFile']['tmp_name']))
{
$currentTime=time();
$pictureName=md5("$currentTime".$_SERVER['REMOTE_ADDR']);
$urlImage="../../sender/".$username."/".$pictureName.".jpg";
$urlThumbnail="../../sender/".$username."/".$pictureName."_thumbnail.jpg";
//we copy the thumbail image
if (copy ($_FILES['ImageFile']['tmp_name'],$urlImage) && LoadJpeg($urlImage,$urlThumbnail))
{
$id=$_COOKIE["id"];
mysql_query("INSERT INTO modelpictures ( user , name, dateuploaded ) VALUES ('$username', '$pictureName', '$currentTime')");
$errorMsg.=' Bild eingefügt';
}
else
{
$errorMsg.="Datei wurde nicht kopiert. Prüfe die Auflösung. Maximum ca. 800x800 Pixel und 100kb.";
}
} else if(isset($_GET['delete']))
{
//unlink("../../sender/$username/$_GET[delete]_thumbnail.jpg");
//unlink("../../sender/$username/$_GET[delete].jpg");
mysql_query('DELETE from modelpictures WHERE name="'.$_GET[delete].'" LIMIT 12'); //Change to maximum upload allowed
$errorMsg+="File Deleted";
}
?>