[insert_php]
include_once ’./ims_files/functions.inc’;
if(!isset($_SESSION[’userOnlineID’])){ exit(js_redirect(’/logga-in’)); }
$path = ’/ims_files/foto/’;
require_once(’./ims_files/menu.inc’);
if(isset($_REQUEST[’submit’]) && !empty($_FILES[’file’][’name’])){
$max_file_size = 1501200;
if(isset($_FILES[’file’][’tmp_name’])){
$filename = $_FILES[’file’][’name’];
$ext = explode(”.”,$filename);
$file_extension = end($ext);
$filename = $_SESSION[’userOnlineID’].’.’.$file_extension;
@copy($_FILES[’file’][’tmp_name’],$path.$filename);
}
//Minska om stort
$pic = getimagesize($path.$filename);
$file_width= $pic[0];
$file_height = $pic[1];
$limit_size = 300;
if($file_width > $limit_size){
//$file_extension = image_type_to_extension($pic[2]);
$dstFile = $filename;
$dstWidth = $limit_size;
$srcFile = $filename;
$jpegQuality = 80;
if(!file_exists($path.$srcFile)){print $path.$srcFile .” n’existe pas!”;return false;}
if(!$dstFile){$dstFile = basename($filename);}
if(!is_writable($dstDir = dirname($dstFile))){print ”$dstDirm, erreur! ”;return false;}
list($srcWidth, $srcHeight, $type, ) = getimagesize($path.$srcFile);
switch ($type){
case 1 : $srcHandle = imagecreatefromgif($path.$srcFile); break;
case 2 : $srcHandle = imagecreatefromjpeg($path.$srcFile); break;
case 3 : $srcHandle = imagecreatefrompng($path.$srcFile); break;
default : print ’Fichier pas valable!’; return false;
}
if(!$srcHandle){print ”Fonction n’est executée! ”;return false;}
// Shrink the photo
$wDevision = $srcWidth/$dstWidth;
$dstHeight = round($srcHeight/$wDevision);
/////////////////////////////////////////////////////////
$dstHandle = imagecreatetruecolor($dstWidth, $dstHeight);
if (!imagecopyresampled($dstHandle,$srcHandle,0,0,0,0,$dstWidth,$dstHeight,$srcWidth,$srcHeight)) {
print ”Fonction imagecopyresampled() n’est executée!”;
return false;
}
imagedestroy($srcHandle);
switch ($type){
case 1 : imagegif($dstHandle, $path.$dstFile); break;
case 2 : imagejpeg($dstHandle, $path.$dstFile, $jpegQuality); break;
case 3 : imagepng($dstHandle, $path.$dstFile); break;
default : print ’Fichier non valable! ’; return false;
}
imagedestroy($dstHandle);
}
$_SESSION[’foto’] = $filename;
//exit(js_redirect(’./profil-foto’));
}
$bild = $_SESSION[’userOnlinePic’];
if(empty($bild)){ $bild = ’nopic.jpg’; }
/*require_once ’./ims_files/db_conn.inc’;
$sql = mysqli_query($conn,”select bild from ims_person where pid = ” . $_SESSION[’userOnlineID’].”;”);
$row = mysqli_fetch_assoc($sql);
!empty($row[’bild’])?$_SESSION[’foto’]=$path.$row[’bild’]:”;
mysqli_close($conn);*/
print ’
’;
[/insert_php]