<?php
try {
$filename = $_FILES['Filedata']['name'];
$filetmpname = $_FILES['Filedata']['tmp_name'];
$fileType = $_FILES["Filedata"]["type"];
$fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 / 1000);
$userid = $_GET['id'];
$car = $_GET['car'];
$profileUploaded = false;
if($car>0)
{
if(!is_dir('images/'.$userid.'/car'))
{
mkdir('images/'.$userid.'/car', 0777, true);
// chmod('images', 0777);
// chmod('images/'.$userid, 0777);
chmod('images/'.$userid.'/car', 0777);
$profileUploaded = move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$userid."/car/carOriginal".$car.".jpg");
}
else
{
// Place file on server, into the images folder
$profileUploaded = move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$userid."/car/carOriginal".$car.".jpg");
}
if($profileUploaded){
$filename = "images/".$userid."/car/carOriginal".$car.".jpg";
// Create image instances
$src = imagecreatefromjpeg($filename);
$dest = imagecreatetruecolor(250, 250);
list($width, $height, $type, $attr) = getimagesize($filename);
if($width > $height){
imagecopyresized($dest, $src, 0, 0, 0, 0, 250 , 250 , $width-intval(($width-$height)) , $height);
}
else if($height >= $width){
imagecopyresized($dest, $src, 0, 0, 0, 0, 250 , 250 , $width, $height - intval(($height-$width)));
}
// Output and free from memory
header('Content-Type: image/jpeg');
imagejpeg($dest, "images/".$userid."/car/car".$car.".jpg");
imagedestroy($dest);
imagedestroy($src);
}
}
else
{
if(!is_dir('images/'.$userid))
{
mkdir('images/'.$userid, 0777, true);
// chmod('images', 0777);
chmod('images/'.$userid, 0777);
$profileUploaded = move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$userid."/profileOriginal.jpg");
// chmod("images/".$userid."/profileOriginal.jpg", 0777);
}
else
{
// Place file on server, into the images folder
$profileUploaded = move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$userid."/profileOriginal.jpg");
}
if($profileUploaded){
$filename = 'images/'.$userid.'/profileOriginal.jpg';
// Create image instances
$src = imagecreatefromjpeg($filename);
$dest = imagecreatetruecolor(250, 250);
list($width, $height, $type, $attr) = getimagesize($filename);
if($width > $height){
imagecopyresized($dest, $src, 0, 0, 0, 0, 250 , 250 , $width-intval(($width-$height)) , $height);
}
else if($height >= $width){
imagecopyresized($dest, $src, 0, 0, 0, 0, 250 , 250 , $width, $height - intval(($height-$width)));
}
// Output and free from memory
header('Content-Type: image/jpeg');
imagejpeg($dest, 'images/'.$userid.'/profile.jpg');
imagedestroy($dest);
imagedestroy($src);
}
}
}
catch (Exception $e)
{
$err = 'Exception caught: '. $e->getMessage(). "\n";
//$myFile = "testfile.txt";
//$fh = fopen($myFile, 'w') or die("can't open file");
//fwrite($fh, $err);
//fclose($fh);
}
?>