Jump to content

[SOLVED] Help with a fatal error code


irishpeck

Recommended Posts

We really need help with this fatal error message were recieving. Basically on our website www.flog-it.ie we allow people to upload images ok. Now in the config.php file we have set jpeg, jpg, png and gif as accepted filetypes and set the maximum file size as being 5000kb ok. But someone just uploaded a .jpeg image that was 260kb and it was 1459px x 1094px and they recieved this error:

 

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 5836 bytes) in /home/sites/flog-it.ie/public_html/common.inc.php on line 548

 

So i went to line 548 in common.inc.php and this is what the code is:

 

$imgsrc = imagecreatefromjpeg($srcfile);

 

The whole code of that area of common.inc is as follows:

 

function SaveResizedJPG($srcfile, $dstfile, $maxw=450, $maxh=325, $quality=75)
{
$imgsrc = imagecreatefromjpeg($srcfile);
$w = $actw = imagesx($imgsrc);
$h = $acth = imagesy($imgsrc);

if (!$maxw) $maxw = 450;
if (!$maxh) $maxh = 325;
if (!$quality) $quality = 75;

if ($w > $maxw)
{
	$w = $maxw;
	$h = round($acth/$actw*$maxw);
}
if ($h > $maxh)
{
	$h = $maxh;
	$w = round($actw/$acth*$maxh);
}

$imgdest = imagecreatetruecolor($w,$h);
imagecopyresampled($imgdest, $imgsrc, 0, 0, 0, 0, $w, $h, $actw, $acth);
return imagejpeg($imgdest, $dstfile, $quality);

 

 

Link to comment
Share on other sites

Try increasing your memory_limit and see if it still causes an error.

 

Chances are the script is not efficient and does not destroy any un-used images that came from the image function. If it left it in memory, it can quickly increase, so a 260KB image, that has been resized, saved and had a thumbnail saved, could potentially have 4-6 times that amount of memory used, depending on the code and if it was done right.

 

Such as in the above, you have $imgsrc that is never set to null, thus it is staying in the memory eating it up.

 

	$imgdest = imagecreatetruecolor($w,$h);
imagecopyresampled($imgdest, $imgsrc, 0, 0, 0, 0, $w, $h, $actw, $acth);
             $imgsrc = null;
             return imagejpeg($imgdest, $dstfile, $quality);

 

Just small/simple items like that will help. If you do not want to re-work the code, increase the memory_limit for a bandaid. If you can have a max of 5000KB image, make the max memory_limit something like 32M or 64M as that should be plenty to handle that.

Link to comment
Share on other sites

Well this is the whole code here so where would i be able to put it?

 

<?php
// Take care of MySQL injection attacks
if(!get_magic_quotes_gpc())
{
addslashes_recurse($_GET);
addslashes_recurse($_POST);
addslashes_recurse($_REQUEST);
}

//wayne's edit - check to see if unique code already exists
function unique_code_exists($code){
$code = intval($code);
$result = mysql_query("SELECT COUNT(*) AS num FROM clf_ads WHERE unique_code = '$code'");
$result2 = mysql_query("SELECT COUNT(*) AS num FROM clf_events WHERE unique_code = '$code'");
list($num) = mysql_fetch_row($result);
list($num2) = mysql_fetch_row($result2);
$num = $num + $num2;
if($num == 0){
	return false;
}
else{
	return true;
}
}

function addslashes_recurse(&$ar)
{
foreach ($ar as $k=>$v)
{
	if(is_array($v)) addslashes_recurse($v);
	else $ar[$k] = addslashes($v);
}
}

// Admin mode
if(isset($_COOKIE[$ck_admin]) && $_COOKIE[$ck_admin]) $admin_logged = TRUE;
else $admin_logged = FALSE;

// Language
if(!isset($path_escape)) $path_escape=NULL;
if (!is_file("{$path_escape}lang/{$language}.inc.php") && !$in_admin)
{
die("Language file not found!");
}

require_once("{$path_escape}lang/{$language}.inc.php");

$xlang = $language;	// For compatibility
$langx['months'] = explode(";", $langx['months']);
$langx['months_short'] = explode(";", $langx['months_short']);
$langx['weekdays'] = explode(";", $langx['weekdays']);
$langx['dateformat'] = str_replace("  ", "  ", $langx['dateformat']);
$langx['datetimeformat'] = str_replace("  ", "  ", $langx['datetimeformat']);

// Current view
if(!isset($_GET['view'])) $_GET['view'] = false;
$xview = $_GET['view'] ? $_GET['view'] : "main";
if(!isset($_GET['search'])) $_GET['search'] = false;
$xsearch = $_GET['search'];
if(!isset($_GET['pricemin'])) $_GET['pricemin'] = false;
if(!isset($_GET['pricemax'])) $_GET['pricemax'] = false;
if(!isset($_GET['x'])) $_GET['x'] = NULL;
$xsearchmode = ($_GET['search'] || $_GET['pricemin'] || $_GET['pricemax'] || count($_GET['x']));

// Get current city
if (isset($_GET['cityid']) && $_GET['cityid'] > 0)
{
$xcityid = $_GET['cityid'];
}
elseif (isset($_GET['cityid']) && $_GET['cityid'] < 0)
{
$xcountryid = abs($_GET['cityid']);
$xcityid = $_GET['cityid'];
}
/*elseif ($_COOKIE[$ck_cityid] > 0)
{
$xcityid = $_COOKIE[$ck_cityid];
}
elseif ($_COOKIE[$ck_cityid] < 0)
{
$xcountryid = abs($_COOKIE[$ck_cityid]);
$xcityid = $_COOKIE[$ck_cityid];
}*/
elseif ($default_city)
{
$xcityid = $default_city;
if($xcityid < 0) $xcountryid = -($xcityid);
}


if ($xcityid)
{
if ($xcityid > 0) $sql = "SELECT COUNT(*) FROM $t_cities WHERE cityid = $xcityid";
else $sql = "SELECT COUNT(*) FROM $t_countries WHERE countryid = $xcountryid";

list($city_exists) = @mysql_fetch_array(mysql_query($sql));
if(!$city_exists) $xcityid = 0;
}

/*if(!$xcityid)
{
$sql = "SELECT countryid
		FROM $t_countries
		WHERE enabled = '1'
		LIMIT 1";
list($xcountryid) = mysql_fetch_array(mysql_query($sql));
$xcityid = 0-$xcountryid;
}*/

if(!$xcityid)
{
$sql = "SELECT cityid
		FROM $t_cities
		WHERE enabled = '1'
		LIMIT 1";
list($xcityid) = @mysql_fetch_array(mysql_query($sql));
}
if(!isset($in_admin)) $in_admin = false;
if (!$xcityid && !$in_admin)
{
die("No locations defined!");
}

setcookie($ck_cityid, $xcityid, 0, "/");

// Get city name
if ($xcityid > 0)
{
$sql = "SELECT c.countryname, c.countryid, ct.cityname
		FROM $t_cities ct
			INNER JOIN $t_countries c ON c.countryid = ct.countryid
		WHERE cityid = $xcityid";
list($xcountryname, $xcountryid, $xcityname)= @mysql_fetch_array(mysql_query($sql));
}
elseif ($xcountryid)
{
$sql = "SELECT c.countryname
		FROM $t_countries c 
		WHERE countryid = $xcountryid";
list($xcountryname)= @mysql_fetch_array(mysql_query($sql));
$xcityname = $xcountryname;
}


// Common metadata
$page_title = "Buy and Sell Anything In Ireland - Find It, Buy It ";
$meta_kw = "Ireland Classified Ads,free,irish,Ireland Classified Ads,Ireland Classified Ads, buy sell online,buy sell,buy and sell,buyandsell,buy & sell,buy&sell,buy and sell ireland,free ads,free classifieds,irish classifieds,classifieds,dogs for sale,add,irelands newest website,irelands newest classifieds, buy anything, sell anything, find what you need, flog it, flog it ireland, flog-it.ie, flog-it, flog-it ireland, flog it.ie, flog your stuff, car for sale, cars for sale, buy and sell anything,buy and sell in Ireland,sell second hand,sell,buy, classifieds, flog, it, flog-it, flog-it.ie, ireland, classified, irelands newest classified, website, cars for sale, motors, holiday in ireland, van for sale, 4 x 4 for sale, business for sale, business oppurtunities, furniture, hotels in ireland, computers, laptops, hardware, dating, friends, diy, construction, events, health and beauty, freebies, travel, holidays, school stuff, propery for sale, property for let, pets, music, entertainment, jobs wanted, jobs offered, jobs, job, Ireland, Irelands newest classifed website, Flog-It, FlogIt, Flog-It.ie, Clothing, Accesories, Shoes, sports, leisure, swap shop, hobbies collectibles, tv's, tv, business services, Ireland , classifieds, classified ads, jobs, for sale, real estate, services, community, events, Ireland classifieds,free classifieds Ireland,online classifieds Ireland,classified ads Ireland, Ireland, free classified ads, classifieds, jobs, dating, singles, real estate, business listings, free classified ads, free classifieds, free online classified ads, free local classifieds, free online classifieds, ads free, classified, classified ads, free classified, buy sell, classifieds, classifieds classified, local classifieds, online classified ads, automobile classified ads, cars, classified ads real estate, collectibles, electronics, events,  free job classifieds, free online car classifieds, free real estate ads, free real estate, Jobs, Dublin, accommodation, rent, Dublin, dating, 20th century antiques,and garden furniture,antiques,antiques and collectables,antiques collectables,antiques guide,antiques price guide,antiques roadshow,auction cars,audi a3 cars,audi cars,auto classified ads,auto classifieds,auto classifieds guide,auto sales ireland,auto salvage cars,automatic car,automatic cars,b&b donegal ireland,bedroom furniture,business development,business for sale,business for sale ireland,business franchise,business opportunities,business opportunity,businesses for sale,buy a franchise,buy car,buy used car,buy used cars,cane furniture,car,car boot sale,car boot sales,car buyers guide,car classifieds,car dealers cork,car for sale,car hire dublin ireland,car hire ireland cork,car history ireland,car rental cork ireland,car rental dublin ireland,car sales,car sales ireland,cars,cars classifieds,cars for sale,
castle hotel cork,cheap car,cheap used car,cheap used cars,city classified ads,classic car,classic car sales,classic cars,classic cars for sale,classified ad jobs,classified ads jobs,classified pets and,classifieds,classifieds ads jobs,classifieds for pets in,construction business for sale,cork ireland vacation,cottage in ireland,cottages in cork ireland,designer furniture,diesel car com,diesel car used,dining furniture,diy garden furniture,donegal ireland hotels,driving jobs ireland,dublin furniture shops,dublin holiday,dublin ireland holiday,dublin ireland vacation package,employment ads,employment classified ads,farm equipment salvage,farm equipment usa,flight ireland,franchise,franchise for sale,franchise ireland,franchise opportunities,franchise opportunity,franchises,franchises for sale,free classifieds for pets,furniture,furniture ireland,furniture online,furniture shop,furniture shops,furniture store,furniture stores,galway holiday,galway ireland hotels,garden furniture,garden furniture bench,garden furniture benches,garden furniture ireland,garden furniture online,holiday accommodation ireland,holiday cottage ireland,holidayhomes ireland,holiday offers ireland,holidays in ireland,hotel in kilkenny ireland,hotel spa jobs,hotels in dublin ireland,hotels ireland cork,in county sligo ireland,in free classifieds,ireland airfares,ireland cottages,ireland flowers,ireland travel info,job ads,job classified ads,jobs and classifieds,kildare ireland hotel,kildare ireland hotels,kitchen furniture,limerick ireland hotel,limerick ireland hotels,look classifieds new job,luxury holiday homes,luxury holiday ireland,luxury hotel offers ireland,map in ireland,massage in dublin ireland,mirrors car,new times classifieds job,newspaper classified ads,oak furniture,oak garden furniture,old farm equipment,outdoor furniture,outdoor garden furniture,patio furniture,pine furniture,pubs for sale,rent farm equipment,rosslare ireland hotels,sales jobs classifieds,salvage car auction,schools ireland dublin,second hand car,second hand cars,second hand cars for sale,secondhand cars,self catering donegal ireland,self catering galway ireland,self catering ireland,self catering ireland ireland,self
catering wexford ireland,sell business,sell car,sell used car,selling a used car,sligo hotels ireland,small business advice,small business for sale,small business information,spa hotels in ireland,spa hotels ireland,sports in ireland,teak garden furniture,the antiques roadshow,
travel ireland map,used audi cars,used car,used car dealer,used car dealers,used car dealers cork,used car dealers ireland,used car dealerships,used car deals,used car for sale,used car prices,used car sale,used car sales,used car search,used cars,used cars diesel,used cars for sale,used cars uk,used volkswagen diesel car,vw diesel cars,waterford ireland hotels,waterford ireland travel,waterford wexford,
wexford ireland hotel,wexford ireland hotels,wicklow ireland travel,wooden garden furniture,";
$meta_desc = "Buy and Sell Anything In Ireland - Find It, Buy It ";

$xsubcatfields = array();



// Search events
if ($xsearchmode && ($_GET['catid'] == -1 || $_GET['subcatid'] == -1))
{
$xview = $_GET['view'] = $_REQUEST['view'] = "events";
unset($_GET['subcatid'], $_GET['catid']);
}


// Find vars and make metadata
if (($xview == "showad" || ($xview == "mailad" && $_GET['adtype'] == "A")) && $_GET['adid'])
{
$xsection = "ads";
$xadtype = "A";
$xpostmode = FALSE;

$sql = "SELECT adtitle, cat.catid, cat.catname as catname, scat.subcatid, scat.subcatname as subcatname
		FROM $t_ads a
			INNER JOIN $t_subcats scat ON scat.subcatid = a.subcatid
			INNER JOIN $t_cats cat ON cat.catid = scat.catid
		WHERE a.adid = $_GET[adid]";
list($adtitle, $xcatid, $xcatname, $xsubcatid, $xsubcatname) = mysql_fetch_array(mysql_query($sql));
$xadid = $_GET['adid'];

$page_title .= " $adtitle";
$meta_kw .= ",$xcatname,$xcatname classified ads,classified ads on $xcatname,$xcatname offers,$xsubcatname,$xsubcatname classified ads,classified ads on $xsubcatname,$xsubcatname offers";
$meta_desc .= "$site_name has posts in $catname and $subcatname and a number of other categories.";

}

elseif ($xview == "ads" && $_GET['subcatid'] > 0)
{
$xsection = "ads";
$xadtype = "A";
$xpostmode = FALSE;

$sql = "SELECT cat.catid, catname as catname, subcatname as subcatname
		FROM $t_subcats scat
			INNER JOIN $t_cats cat ON cat.catid = scat.catid
		WHERE scat.subcatid = $_GET[subcatid]";
list($xcatid, $xcatname, $xsubcatname) = mysql_fetch_array(mysql_query($sql));
$xsubcatid = $_GET['subcatid'];


if($xsearch)
{
	$searchinttile = "'$xsearch'";

	//if ($_GET['pricemin'] && $_GET['pricemax']) $searchinttile .= " between $currency $_GET[pricemin]  and $_GET[pricemax] ";
	//if ($_GET['pricemin']) $searchinttile .= " above $currency $_GET[pricemin]";
	//if ($_GET['pricemax']) $searchinttile .= " below $currency $_GET[pricemax]";

	//$page_title .= " Search results for $searchinttile in $xcatname > $xsubcatname";
	$page_title .= " $lang[sEARCH] - $searchinttile";

}
else
{
	$page_title .= " $lang[sHOWING_ADS_IN] $xcatname > $xsubcatname";
}

$meta_kw .= ",$xcatname,$xcatname classified ads,classified ads on $xcatname,$xcatname offers,$xsubcatname,$xsubcatname classified ads,classified ads on $xsubcatname,$xsubcatname offers";
$meta_desc .= "$site_name has posts in $catname and $subcatname and a number of other categories.";
}

elseif (($xview == "ads" || $xview == "subcats") && $_GET['catid'])
{
$xsection = "ads";
$xadtype = "A";
$xpostmode = FALSE;

$sql = "SELECT catname as catname
		FROM $t_cats cat
		WHERE cat.catid = $_GET[catid]";
list($xcatname) = mysql_fetch_array(mysql_query($sql));

$xcatid = $_GET['catid'];

if($xsearch)
{
	//$page_title .= " Search results for '$xsearch' in $xcatname";
	$page_title .= " $lang[sEARCH] - '$xsearch'";
}
else
{
	$page_title .= " $lang[sHOWING_ADS_IN] $xcatname";
}

$meta_kw .= ",$xcatname,$xcatname classified ads,classified ads on $xcatname,$xcatname offers";
$meta_desc .= "$site_name has posts in $catname and $subcatname and a number of other categories.";
}

elseif (($xview == "showevent" || ($xview == "mailad" && $_GET['adtype'] == "E")) && $_GET['adid'])
{
$xsection = "events";
$xadtype = "E";
$xpostmode = FALSE;

$xcatname = $lang['EVENTS'];
$xadid = $_GET['adid'];
$xcatid = -1;
$xsubcatid = -1;

$sql = "SELECT adtitle FROM $t_events WHERE adid = $xadid";
list($adtitle) = mysql_fetch_array(mysql_query($sql));

if ($_GET['date']) $xdate = $_GET['date'];
else $xdate = date("Y-m-d");

$page_title .= " $adtitle (Event on $xdate)";
$meta_kw .= ",event calendar,events,classes,functions,meetings,announcements,events on $xdate,classes on $xdate,functions on $xdate,meetings on $xdate,announcements on $xdate";
}

elseif ($xview == "events")
{
$xsection = "events";
$xadtype = "E";
$xpostmode = FALSE;

$xcatname = $lang['EVENTS'];
$xsubcatname = $lang['EVENTS'];
$xcatid = -1;
$xsubcatid = -1;

if ($_GET['date']) 
{
	$xdate = $_GET['date'];
	$urldate = $xdate;
	$page_title .= " - $xdate";
	$meta_kw .= ",events on $xdate,classes on $xdate,functions on $xdate,meetings on $xdate,announcements on $xdate";
}
else 
{
	$xsearchmode = TRUE;
}

$page_title .= " Event Calendar";
$meta_kw .= ",event calendar,events,classes,functions,meetings,announcements";

}

elseif ($xview == "imgs")
{
$xsection = "imgs";
$xadtype = "I";
$xpostmode = FALSE;

$page_title .= " Images";
$xposterenc = $_GET['posterenc'];
if ($xposterenc)
{
	$sql = "SELECT postername, posteremail FROM $t_imgs WHERE MD5(CONCAT('IMG', '$encryptposter_sep', postername, '$encryptposter_sep', posteremail)) = '$xposterenc' LIMIT 1";
	$res = mysql_query($sql) or die(mysql_error());
	list($xpostername, $xposteremail) = mysql_fetch_array($res);
	$page_title .= " by $xpostername";
}

}

elseif ($xview == "showimg")
{
$xsection = "imgs";
$xadtype = "I";
$xpostmode = FALSE;

$ximgid = $_GET['imgid'];
$sql = "SELECT imgtitle, postername, posteremail, showemail FROM $t_imgs WHERE imgid = $ximgid";
list($ximgtitle, $xpostername, $xposteremail, $xshowposteremail) = mysql_fetch_array(mysql_query($sql));
$xposterenc = EncryptPoster("IMG", $xpostername, $xposteremail);
$page_title .= " Images by $xpostername - $ximgtitle";
}

if ($xview == "post" || $xview == "edit")
{
$xsection = ($_REQUEST['postevent'] || $_REQUEST['isevent']) ? "events" : "ads";
$xadtype = ($_REQUEST['postevent'] || $_REQUEST['isevent']) ? "E" : "A";;
$xpostmode = TRUE;

$xcatid = $_GET['catid'];
$xsubcatid = $_GET['subcatid'];
}
else if ($xview == "postimg" || $xview == "editimg")
{
$xsection = "imgs";
$xadtype = "I";
$xpostmode = TRUE;
}
elseif ($xview == "selectcity")
{
$xpostmode = TRUE;
}

$meta_desc .= "$site_name has an event calendar also to post important events, classes, shows etc.";
$page_title = ($xcityid>0 ? "$xcityname, " : "") . "$xcountryname" . ($page_title ? ": " : "" ) . "$page_title - $site_name";


// Find subcat specific fields
if(!isset($xsubcatid)) $xsubcatid = false;
if ($xsubcatid)
{
list($xsubcathasprice, $xsubcatpricelabel, $xsubcatfields) = GetCustomFields($xsubcatid);
}


// Make timestamp of $xdate
if(!isset($xdate)) $xdate = false;
if ($xdate)
{
preg_match("/([0-9]+)-([0-9]+)-([0-9]+)/", $xdate, $dp);
$xdatestamp = mktime(0, 0, 0, $dp[2], $dp[3], $dp[1]);
$xdate_y = $dp[1];
$xdate_m = $dp[2];
$xdate_d = $dp[3];
}


// Location condition
if($xcityid > 0)
{
$loc_condn = $city_condn = "AND a.cityid = $xcityid";
$loc_condn_img = "AND a.cityid = $xcityid";
}
else
{
$loc_condn = $country_condn = "AND ct.countryid = $xcountryid";
$loc_condn_img = "AND ct.countryid = $xcountryid";
}


// Visibility condition
$visibility_condn = "a.enabled = '1' AND a.verified = '1' AND a.expireson >= NOW()";

if($admin_logged) $visibility_condn_admin = "1";
else $visibility_condn_admin = "a.enabled = '1' AND a.verified = '1' AND a.expireson >= NOW()";


// Post link
$postlink = "$script_url/index.php?view=post";
if(!isset($xcatid)) $xcatid = false;
if ($xcatid) $postlink .= "&catid=$xcatid";
if ($xsubcatid) $postlink .= "&subcatid=$xsubcatid";
if ($xview == "events" || $xview == "showevent") $postlink .= "&postevent=1";
$postlink .= "&cityid=$xcityid&lang=$xlang";

// Post ad link
$postadlink = "index.php?view=post";
if ($xcatid > 0) $postadlink .= "&catid=$xcatid";
if ($xsubcatid > 0) $postadlink .= "&subcatid=$xsubcatid";
$postadlink .= "&cityid=$xcityid";

// Post event link
$posteventlink = "index.php?view=post&postevent=1&cityid=$xcityid";

// Post image link
$postimagelink = "index.php?view=postimg&cityid=$xcityid";


// Find cell width for directory based on $dir_cols
$cell_width = round(100/$dir_cols);



/*--------------------------------------------------+
| FUNCTIONS                                         |
+--------------------------------------------------*/


function FilterBadWords($str)
{
global $path_escape, $badword_replacement, $datafile;

$w = array();
$fp = fopen("{$path_escape}{$datafile[badwords]}", "r");
while($s=fgets($fp, 1024)) { if($s=trim($s)) $w[] = $s; }
fclose($fp);

// Note: Call preg_replace twice. Otherwise it wont replace consecutive bad words.
$wordlist = implode("|", $w);
$str = preg_replace("/(^|[^\w])($wordlist)([^\w]|$)/i", "\\1{$badword_replacement}\\3", $str);
$str = preg_replace("/(^|[^\w])($wordlist)([^\w]|$)/i", "\\1{$badword_replacement}\\3", $str);

return $str;
}

function QuickDate($timestamp, $showtime=TRUE, $gmt=FALSE, $format="")
{
if(!$format)
{
	if($showtime) $format = $GLOBALS['langx']['datetimeformat'];
	else $format =  $GLOBALS['langx']['dateformat'];
}

return xDate($timestamp, $gmt, $format, $GLOBALS['langx']['months'], $GLOBALS['langx']['weekdays']);
}

function EncryptPoster($section, $postername, $posteremail)
{
global $encryptposter_sep;
return md5("$section$encryptposter_sep$postername$encryptposter_sep$posteremail");
}

function GetCustomFields($subcatid)
{
global $xfields_count, $t_subcats, $t_subcatxfields;

$sql = "SELECT hasprice, pricelabel
		FROM $t_subcats
		WHERE subcatid = $subcatid";
list($hasprice, $pricelabel) = mysql_fetch_array(mysql_query($sql));

// Get custom fields
$sql = "SELECT * FROM $t_subcatxfields WHERE subcatid = $subcatid LIMIT $xfields_count";
$res = mysql_query($sql) or die($sql.mysql_error());

$subcatfields = array();
while($row=mysql_fetch_array($res))
{
	$subcatfields[$row['fieldnum']] = array("NAME"=>$row["name"], 
											"TYPE"=>$row['type'], 
											"VALUES"=>$row['vals'],
											"VALUES_A"=>explode(";",$row['vals']),
											"SHOWINLIST"=>$row['showinlist'],
											"SEARCHABLE"=>$row['searchable']);
}

return(array($hasprice, $pricelabel, $subcatfields));
}

function GetDateSelectOptions($seld=0, $selm=0, $sely=0)
{
global $langx;

$dlist = "";
for($i=1; $i<=31; $i++) $dlist .= "<option value=\"$i\"".($seld==$i?" selected":"").">$i</option>\n";

$mlist = "";
for ($i=1; $i<=12; $i++) $mlist .= "<option value=\"$i\"".($selm==$i?" selected":"").">".$langx['months'][$i-1]."</option>\n";

$ylist = "";
$thisy = date("Y");
for ($i=2005; $i<=$thisy; $i++) $ylist .= "<option value=\"$i\"".($sely==$i?" selected":"").">$i</option>";

return (array("D"=>$dlist, "M"=>$mlist, "Y"=>$ylist));
}

function IPVal($ip = "")
{
if(!$ip) $ip = $_ENV['REMOTE_ADDR'];
preg_match("/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/U", $ip, $ipp);
$ipval = $ipp[4] + $ipp[3]*256 + $ipp[2]*256*256 + $ipp[1]*256*256*256;
return  $ipval;
}

function RemoveBadURLChars($str)
{
return preg_replace("/[^0-9a-zA-Z]+/", "_", $str);
}

function SaveUploadFile($file, $dir, $resize=TRUE, $maxw=0, $maxh=0, $quality=75)
{
if(!$GLOBALS['image_verification']) $resize = FALSE;

if ($file['tmp_name'])
{
	$dotpos = strrpos($file['name'], ".");

	if ($dotpos) $ext = strtolower(substr($file['name'], $dotpos));
	else $ext = "";

	$newname = uniqid("") . substr(md5($file['name']), 5, 12) . $ext;

	if ($resize && ($ext==".jpg" || $ext==".jpeg" || $ext==".jfif")) $copysuccess = SaveResizedJPG($file['tmp_name'], "$dir/$newname", $maxw, $maxh, $quality);
	else $copysuccess = copy($file['tmp_name'], "$dir/$newname");

	if ($copysuccess)
		$ret = $newname;
	else
		return "";

	unlink($file['tmp_name']);
	return $ret;
}
else
{
	return "";
}
}


function SaveResizedJPG($srcfile, $dstfile, $maxw=450, $maxh=325, $quality=75)
{
$imgsrc = imagecreatefromjpeg($srcfile);
$w = $actw = imagesx($imgsrc);
$h = $acth = imagesy($imgsrc);

if (!$maxw) $maxw = 450;
if (!$maxh) $maxh = 325;
if (!$quality) $quality = 75;

if ($w > $maxw)
{
	$w = $maxw;
	$h = round($acth/$actw*$maxw);
}
if ($h > $maxh)
{
	$h = $maxh;
	$w = round($actw/$acth*$maxh);
}

$imgdest = imagecreatetruecolor($w,$h);
imagecopyresampled($imgdest, $imgsrc, 0, 0, 0, 0, $w, $h, $actw, $acth);
$imgsrc = null;
return imagejpeg($imgdest, $dstfile, $quality);

}

function xMail($to, $subj, $msg, $from="", $charset="UTF-8", $xtraheaders="")
{
$headers  = "";
if($from) $headers .= "From: {$from}\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=\"$charset\"\n";
$headers .= "Content-Transfer-Encoding: 7bit\n";
$headers .= $xtraheaders;
$headers .= "\n";

$ret = mail ($to, $subj, $msg, $headers, "-f$from");
return $ret;

}

function HTMLMail($to, $subj, $msg, $from="", $charset="UTF-8", $xtraheaders="")
{
$headers  = "";
if($from) $headers .= "From: {$from}\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=\"$charset\"\n";
$headers .= "Content-Transfer-Encoding: 7bit\n";
$headers .= $xtraheaders;

$ret = mail ($to, $subj, $msg, $headers, "-f$from");
return $ret;

}

function xStripSlashes($str)
{
if(get_magic_quotes_gpc()) return stripslashes($str);
else return $str;
}

function xDate($timestamp, $gmt=FALSE, $format="{l}, {d} {M}, {Y} {H}:{i}", $months="", $weekdays="")
{
if(!$months) $months = array("January","February","March","April","May","June","July","August","September","October","November","December");
if(!$weekdays) $weekdays = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

$datetplformat = "w d n Y H i s j";
$datetpl = $gmt ? gmdate($datetplformat, $timestamp) : date($datetplformat, $timestamp);
$dateparts = explode(" ", $datetpl);

$date = $format;
$date = str_replace("{l}", $weekdays[$dateparts[0]], $date);
$date = str_replace("{d}", $dateparts[1], $date);
$date = str_replace("{M}", $months[$dateparts[2]-1], $date);
$date = str_replace("{Y}", $dateparts[3], $date);
$date = str_replace("{H}", $dateparts[4], $date);
$date = str_replace("{i}", $dateparts[5], $date);
$date = str_replace("{s}", $dateparts[6], $date);
$date = str_replace("{j}", $dateparts[7], $date);
$date = str_replace("{g}", $dateparts[8], $date);
$date = str_replace("{a}", $dateparts[9], $date);

return $date;
}

function ValidateEmail($email)
{
global $debug;
if($debug) return TRUE;
else return preg_match("/^[^\s]+@[^\s]+\.[^\s]+$/", $email);
}

function xSetCookie($name, $value)
{
setcookie($name, $value, 0, "/");
}

function GetThumbnailSize($imgfilename, $maxw, $maxh)
{
$origsize = @getimagesize($imgfilename);
$newsize = array($origsize[0], $origsize[1]);

if ($newsize[0] > $maxw)
{
	$newsize[0] = $maxw;
	$newsize[1] = round($origsize[1]/$origsize[0]*$maxw);
}
if ($newsize[1] > $maxh)
{
	$newsize[1] = $maxh;
	$newsize[0] = round($origsize[0]/$origsize[1]*$maxh);
}

return $newsize;
}


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.