when i attempt to call an image form this script, I just get the default value of an email based upon gender.
In order to avoid segfaults on a very busy site thats littered with images, i created a function that takes a userid, devides it by 100000, then devides it again by 4. While the uploading of the images work, i cant for the life of me get them to display in my smarty template.. Please help
<?php
ob_start();
if ( !defined( 'SMARTY_DIR' ) ) {
include_once( 'mini.php' );
}
include('core/snaps_functions.php');
if (isset($_REQUEST['username']) && $_REQUEST['username'] != '') {
$userid = $osDB->getOne('select id from ! where username = ?',array(USER_TABLE, $_REQUEST['username']) );
} else {
// include ( 'sessioninc.php' );
if( !isset($_GET['id']) || (isset($_GET['id'])&& (int)$_GET['id'] <= 0 ) ) {
$userid = $_SESSION['UserId'];
} else {
$userid = $_GET['id'];
}
}
if (!isset($_GET['picid']) ) {
if ((isset($_REQUEST['type']) && $_REQUEST['type'] != 'gallery') || !isset($_REQUEST['type']) ) {
$defpic = $osDB->getOne('select picno from ! where userid = ? and ( album_id is null or album_id = ?) and default_pic = ? and active = ? ',array(USER_SNAP_TABLE, $userid,'0','Y','Y' ) );
if ($defpic != '') {
$picid = $defpic;
} else {
$picid = $osDB->getOne('select picno from ! where userid = ? and ( album_id is null or album_id = ?) and active=? order by rand()',array(USER_SNAP_TABLE, $userid,'0','Y' ) );
}
unset( $defpic);
}
} else {
$picid = $_GET['picid'];
}
$typ = isset( $_GET['typ'])?$_GET['typ']:'pic' ;
$cond = '';
if ( ($config['snaps_require_approval'] == 'Y' || $config['snaps_require_approval'] == '1') && $userid != $_SESSION['UserId'] ) {
$cond = " and active = 'Y' ";
}
$sql = 'select * from ! where userid = ? and picno = ? '.$cond;
//Get the pic
$row =& $osDB->getRow ( $sql, array( USER_SNAP_TABLE, $userid, $picid ) );
//Okay pic was found in the DB, Lets actually do something
//
$id = $userid;
$dir = str_pad(($id - ($id % 1000))/100000,6,'0',STR_PAD_LEFT);
$zimg = USER_IMAGES_DIR.$dir;
$img = getPicture($userid, $picid, $typ, $row);
//$img = getPicture($dir, $userid, $picid, $typ, $row);
$ext = ($typ = 'tn')?$row['tnext']:$row['picext'];
// Now pic is built as
// something pic_x.ext ie pic_2.jpg
if ( $img != '' && ( ( hasRight('seepictureprofile') && ( $config['snaps_require_approval'] == 'Y' && $row['active'] == 'Y' ) ||$config['snaps_require_approval'] == 'N' ) || $userid == $_SESSION['UserId'] ) ) {
$img2 = $img;
//$img2 = $dir.'/'.$img;
} else {
$gender = $osDB->getOne( 'select gender from ! where id = ?', array( USER_TABLE, $userid ) ) ;
if ($gender == 'M') {
$nopic = SKIN_IMAGES_DIR.'male.jpg';
} elseif ($gender == 'F') {
$nopic = SKIN_IMAGES_DIR.'female.jpg';
} elseif ($gender == 'D') {
$nopic = SKIN_IMAGES_DIR.'director.jpg';
}
$img2 = imagecreatefromjpeg($nopic);
$ext = 'jpg';
}
ob_end_clean();
header("Pragma: public");
header("Content-Type: image/".$ext);
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate");
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() - 30) . " GMT";
header($ExpStr);
//header("Content-Disposition: attachment; filename=profile_".$userid."_".$typ.".".$ext);
//header("Content-Disposition: attachment; filename=$dir.'/'.profile_".$userid."_".$typ.".".$ext);
//header("Content-Disposition: attachment; filename=profile_"$dir".'/'.".$userid."_".$typ.".".$ext);
//header("Content-Disposition: attachment; filename=profile_".$userid."_".$typ.".".$ext);
header("Content-Disposition: attachment; filename=profile_".$userid."_".$typ.".".$ext);
//$img = getPicture($userid, $picid, $typ, $row);
/*
if ($_SESSION['browser'] != 'MSIE') {
header("Content-Disposition: inline" );
}
*/
if ($ext == 'jpg') {
imagejpeg($img2);
} elseif ($ext == 'gif') {
imagegif($img2);
} elseif ($ext == 'png') {
imagepng($img2);
} elseif ($ext == 'bmp') {
imagewbmp($img2);
}
imagedestroy($img2);
?>