function imageUploadExceedsMemory($info) { $memoryLimit = byteStr2num(ini_get('memory_limit')); if (function_exists('memory_get_usage') && $memoryLimit && $memoryLimit != -1) { $channels = isset($info['channels']) ? $info['channels'] : 1; // png has no channels $memoryNeeded = Round(($info[0] * $info[1] * $info['bits'] * $channels / 8 + Pow(2, 16)) * 1.65); $usage = memory_get_usage(); //FP::log("Current usage: $usage, limit: $memoryLimit, new to allocate: $memoryNeeded, rest after allocate: ". ($memoryLimit-$usage-$memoryNeeded)); // skipping if ImageCreate would exceed the memory limit: return $usage + $memoryNeeded > $memoryLimit; } return FALSE; }
function checkForPostMaxSizeError() { if (!isset($_SERVER['CONTENT_LENGTH'])) { return; } $POST_MAX_SIZE = byteStr2num(ini_get('post_max_size')); if ($POST_MAX_SIZE && $_SERVER['CONTENT_LENGTH'] > $POST_MAX_SIZE) { Roll::setFormInvalid("postMaxSizeExceeded", $POST_MAX_SIZE); LocationHistory::saveInfoText(); LocationHistory::rollBack(2); } }
function updateItemTable() { global $thumbnailSizes; executeQueryForUpdate("\n ALTER TABLE @item \n DROP title, DROP picture, DROP keepPrivate,\n CHANGE `active` `status` INT NOT NULL DEFAULT 1, \n CHANGE `expirationTime` `expirationTime` DATETIME NOT NULL, \n CHANGE `creationtime` `creationtime` DATETIME NOT NULL;", __FILE__, __LINE__); executeQueryForUpdate("UPDATE @item SET `expirationTime`=0, expEmailSent=0", __FILE__, __LINE__); G::load($cats, "SELECT * FROM @category WHERE expiration!=0"); foreach ($cats as $cat) { executeQueryForUpdate("UPDATE @item SET `expirationTime`= NOW() + INTERVAL {$cat->expiration} DAY WHERE cid={$cat->id};", __FILE__, __LINE__); } CustomField::addCustomColumns("item"); G::load($items, "SELECT * FROM @item WHERE col_1!=''"); $create_fg = array("", "ImageCreateFromGIF", "ImageCreateFromJPEG", "ImageCreateFromPNG"); $save_fg = array("", "ImageGIF", "ImageJPEG", "ImagePNG"); $extensions = array("", "gif", "jpg", "png"); $checkBits = array(0, IMG_GIF, IMG_JPG, IMG_PNG); $memoryLimit = byteStr2num(ini_get('memory_limit')); foreach ($items as $item) { $ext = strstr($item->col_1, "jpg") ? "jpg" : (strstr($item->col_1, "gif") ? "gif" : (strstr($item->col_1, "png") ? "png" : "")); if (!$ext) { continue; } executeQueryForUpdate("UPDATE @item SET col_1='{$ext}' WHERE id={$item->id}", __FILE__, __LINE__); $fname = AD_PIC_DIR . "/{$item->id}.{$ext}"; if (file_exists($fname)) { @unlink(AD_PIC_DIR . "/th_{$item->id}.{$ext}"); // a regi thumbnailt toroljuk copy($fname, AD_PIC_DIR . "/{$item->id}_1.{$ext}"); // uj nev a full image-nek // mas fg-eket kell hivni az image tipusnak megfeleloen: $size = getimagesize($fname); $width = $size[0]; $height = $size[1]; $type = $size[2]; // az image tipus, 1=>GIF, 2=>JPG, 3=>PNG $ext = $extensions[$type]; $supported = FALSE; if (defined("IMG_GIF") && function_exists("ImageTypes")) { $supported = isset($checkBits[$type]) && ImageTypes() & $checkBits[$type]; } // ha az adott image tipus supportalva van: if ($supported) { foreach ($thumbnailSizes as $thSize => $dimensions) { if (function_exists('memory_get_usage') && $memoryLimit && $memoryLimit != -1) { $channels = isset($size['channels']) ? $size['channels'] : 1; // png has no channels $memoryNeeded = Round(($size[0] * $size[1] * $size['bits'] * $channels / 8 + Pow(2, 16)) * 1.65); $usage = memory_get_usage(); //FP::log("Current usage: $usage, limit: $memoryLimit, new to allocate: $memoryNeeded, rest after allocate: ". ($memoryLimit-$usage-$memoryNeeded)); // skipping if ImageCreate would exceed the memory limit: if ($usage + $memoryNeeded > $memoryLimit) { continue; } } shrinkPicture($newWidth, $newHeight, $dimensions["width"], $dimensions["height"], $fname); $src_im = $create_fg[$type]($fname); $dst_im = ImageCreateTrueColor($newWidth, $newHeight); imagecopyresampled($dst_im, $src_im, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); $th_foname = AD_PIC_DIR . "/th_{$thSize}_{$item->id}_1.{$ext}"; // pictures/ads/th_medium_2345_5.jpg $save_fg[$type]($dst_im, $th_foname); imagedestroy($src_im); } } @unlink($fname); // a full image-et a regi neven toroljuk } } global $gorumuser, $gorumrecognised; $gorumrecognised = TRUE; $gorumuser->isAdm = 1; $c = new AppCategory(); $c->recalculateAllItemNums(TRUE); }