+ -
当前位置:首页 → 问答吧 → PHP好的特性别放过-匿名方法'

PHP好的特性别放过-匿名方法'

时间:2007-11-24

来源:互联网

复制PHP内容到剪贴板
PHP代码:
/**
  * @desc Resize image
  * @auther  BianYuan
  * @param String  $imageFrom
  * @param Integer $maxwidth
  * @param Integer $maxheight
  * @distDir String  $distDir
  * @return  Boolean
*/
function imageResize($source, $maxwidth=90, $maxheight=110, $distDir=""){
    $imgName = basename($source);
    $output = ""; 匿名方法
    //if some user upload very large imagest.....
    @ list($width, $height, $type) = getimagesize($source);
    switch ($type) 
  { 
   case 1:
    $imageFrom = imagecreatefromgif($source);
    $output = "imagegif";
    break; 
   case 2: 
    $imageFrom = imagecreatefromjpeg($source);
    $output = "imagejpeg";
    break; 
   case 3:
    $imageFrom = imagecreatefrompng($source);
    $output = "imagepng";
    break; 
   default: 
    return false;
    }
    if(! $img = @ imagecreatetruecolor($maxwidth, $maxheight)){
      return false;
    }
    if(($width > $maxwidth) || ($height > $maxheight)){
   imagecopyresampled($img, $imageFrom, 0, 0, 0, 0, $maxwidth, $maxheight, $width, $height);
   $output ($img, $distDir ."/". $imgName);
   ImageDestroy ($img);
  }else{
   if(! @ copy($source, $distDir ."/". $imgName)){
    return false;
   }
  }
  return true;
}

ini_set('memory_limit', '-1');全局设置中这个别忘了设置
复制PHP内容到剪贴板
PHP代码:

<?php
/**
  * @company     xingquan
  * @auther  BianYuan
  * @date     Wed Nov 07 16:24:35 CST 2007
  * @copyright  xingQuan
  * @file        common.inc.php
  * @version   0.1
*/
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
define('UPLOAD', ROOT . DS . "upload");
// Security option
define('IN_SITE', true);
// Display no errors
error_reporting(E_ALL ^ E_NOTICE);
// Sets the time zone for the DateTime object
ini_set('date.timezone','Asia/Shanghai');
// Auto load php file path, like windows $PATH
ini_set('include_path', ini_get('include_path') 
    . PATH_SEPARATOR . ROOT . DS .  'librarys/Pear/');
ini_set('memory_limit', '-1');
// Load core file
require_once("DB.php");
require_once("Pager/Pager.php");
require_once(ROOT . DS . "librarys/config.inc.php");
require_once(ROOT . DS . "librarys/function.inc.php");
require_once(ROOT . DS . "librarys/Class/tpl.class.php");
$tpl = new Tpl();
$options = getOption();
$tpl->assign('options', $options);
header('Content-Type: text/html; charset=utf-8');
?>

[ 本帖最后由 liuxingyuyuni 于 2007-11-24 14:01 编辑 ]

作者: liuxingyuyuni   发布时间: 2007-11-24

作者: luzhou   发布时间: 2007-11-24