Fetch image from folder via datatable does not work after placing image in subdirectory
Posted
by Arnold Bishkoff
on Stack Overflow
See other posts from Stack Overflow
or by Arnold Bishkoff
Published on 2010-06-09T16:29:14Z
Indexed on
2010/06/09
16:32 UTC
Read the original article
Hit count: 237
I am having trouble wrapping my head around the following
I have code that fetches an image via smarty in a line
img src="getsnap.php?picid={$data[$smarty.section.sec.index].picno|default:$nextpic}&typ=pic&width={$config.disp_snap_width}&height={$config.disp_snap_height}" class="smallpic" alt="" />
this works if i pull the image from /temp/userimages/userid/imageNo.ext
but because an OS can segfault if you store too many folders or images in a directory i have code that assigns the user image to a subdirectory based upon division of a subdir per 1000 userids. so in thise case i have user id 94 whos images get stored in /siteroot/temp/userimages/000000/94/pic_1.jpg (through 10) or tn_1 (through 10).jpg
here is the code for getsnap.php
<?php
ob_start();
if ( !defined( 'SMARTY_DIR' ) ) { include_once( 'init.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($zimg, $userid, $picid, $typ, $row); //$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);
$id = $userid;
$dir = str_pad(($id - ($id % 1000))/100000,6,'0',STR_PAD_LEFT);
$zimg = USER_IMAGES_DIR.$dir;
//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);
/* 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); ?>
© Stack Overflow or respective owner