日期:2011-08-16  浏览次数:20836 次

 

upload.php
 
<?php
/*
 * swfupload图片上传  
 */ 
    if (isset($_POST["PHPSESSID"])) {
        session_id($_POST["PHPSESSID"]);
    }
    session_start();
    ini_set("html_errors", "0");
    if (!isset($_FILES["Filedata"]) !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) $_FILES["Filedata"]["error"] != 0) {
        echo "错误:无效的上传!";
        exit(0);
    }
 
    // Get the image and create a thumbnail
     $file_types=explode(".",$_FILES["Filedata"]["name"]);
     $file_type=$file_types[count($file_types)-1];
    if(strtolower($file_type)=='gif' )
    {
        $img = imagecreatefromgif($_FILES["Filedata"]["tmp_name"]);
    }
    else if(strtolower($file_type)=='png')
    {
        $img = imagecreatefrompng($_FILES["Filedata"]["tmp_name"]);
    }
    else if(strtolower($file_type)=='bmp')
    {
        $img = imagecreatefromwbmp($_FILES["Filedata"]["tmp_name"]);
    }
    else
    {
        $img = imagecreatefromjpeg($_FILES["Filedata"]["tmp_name"]);
    }
 
    if (!$img) {
        echo "错误:无法创建图像 ". $_FILES["Filedata"]["tmp_name"];
        exit(0);
    }
 
    $width = imageSX($img);
    $height = imageSY($img);
 
    if (!$width !$height) {
        echo "错误:无效的高或高";
        exit(0);
    }
 
    // Build the thumbnail
    $target_width = 100;
    $target_height = 100;
    $target_ratio = $target_width / $target_height;
 
    $img_ratio = $width / $height;
 
    if ($target_ratio > $img_ratio) {
        $new_height = $target_height;
        $new_width = $img_ratio * $target_height;
    } else {
        $new_height = $target_width / $img_ratio;
        $new_width = $target_width;
    }
 
    if ($new_height > $target_height) {
        $new_height = $target_height;
    }
    if ($new_width > $target_width) {
        $new_height = $target_width;
    }
 
    $new_img = ImageCreateTrueColor(100, 100);
    if (!@imagefilledrectangle($new_img, 0, 0, $target_width-1, $target_height-