ssouf

업로드 본문

Web DEV/PHP

업로드

황금니 2010. 9. 7. 17:52

<?
class upload
{
    public $upload_tmpFileName = null;
    public $upload_fileName = null;
    public $upload_fileSize = null;
    public $upload_fileType = null;
    public $upload_fileWidth = null;
    public $upload_fileHeight = null;
    public $upload_fileExt = null;
    public $upload_fileImageType = null;
    public $upload_count = 0;
    public $upload_directory = null;
    public $upload_subdirectory = null;
    public $denied_ext = array
    (
        "php"    => ".phps",
        "phtml"    => ".phps",
        "html"    => ".txt",
        "htm"    => ".txt",
        "inc"    => ".txt",
        "sql"    => ".txt",
        "cgi"    => ".txt",
        "pl"    => ".txt",
        "jsp"    => ".txt",
        "asp"    => ".txt",
        "phtm"    => ".txt"
    );

    public function __construct($upload_dir)
    {
        $this->upload_directory = $upload_dir;
        $this->upload_subdirectory = time();
    }

    public function define($files)
    {
        if(is_array($files['tmp_name']))
        {
            for($i = 0; $i < sizeof($files['tmp_name']); $i++)
            {
                $this->_uploadErrorChecks($files['error'][$i], $files['name'][$i]);

                if(is_uploaded_file($files['tmp_name'][$i]))
                {
                    $this->upload_tmpFileName[$i] = $files['tmp_name'][$i];
                    $this->upload_fileName[$i] = $this->_emptyToUnderline($this->_checkFileName($files['name'][$i]));
                    $this->upload_fileSize[$i] = (int) $files['size'][$i] ? $files['size'][$i] : 0;
                    $this->upload_fileType[$i] = $files['type'][$i];
                    $this->upload_fileExt[$i] = $this->_getExtension($files['name'][$i]);

                    // 이미지 파일
                    if($this->_isThisImageFile($files['type'][$i]) == true)
                    {
                        $img = $this->_getImageSize($files['tmp_name'][$i]);
                        $this->upload_fileWidth[$i] = (int) $img[0];
                        $this->upload_fileHeight[$i] = (int) $img[1];
                        $this->upload_fileImageType[$i] = $img[2];
                    }
                }
            }
        }
        else
        {
            $this->_uploadErrorChecks($files['error'], $files['name']);

            if(is_uploaded_file($files['tmp_name']))
            {
                $this->upload_tmpFileName = $files['tmp_name'];
                $this->upload_fileName = $this->_emptyToUnderline($this->_checkFileName($files['name']));
                $this->upload_fileSize = (int) ($files['size']) ? $files['size'] : 0;
                $this->upload_fileType = $files['type'];
                $this->upload_fileExt = $this->_getExtension($files['name']);

                // 이미지 파일
                if($this->_isThisImageFile($files['type']) == true)
                {
                    $img = $this->_getImageSize($files['tmp_name']);
                    $this->upload_fileWidth = $img[0];
                    $this->upload_fileHeight = $img[1];
                    $this->upload_fileImageType = $img[2];
                }
            }
        }
    }

    private function _isThisImageFile($type)
    {
        if(preg_match("/image/i", $type) == false && preg_match("/flash/", $type) == false)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    private function _uploadErrorChecks($errorCode, $fileName)
    {
        if($errorCode == UPLOAD_ERR_INI_SIZE)
        {
            throw new Exception($fileName . " : 업로드 제한용량(".ini_get('upload_max_filesize').")을 초과한 파일입니다.");
        }
        else if($errorCode == UPLOAD_ERR_FORM_SIZE)
        {
            throw new Exception($fileName . " : 업로드한 파일이 HTML 에서 정의되어진 파일 업로드 제한용량을 초과하였습니다.");
        }
        else if($errorCode == UPLOAD_ERR_PARTIAL)
        {
            throw new Exception("파일이 일부분만 전송되었습니다. ");
        }
    }

    private function _mkUploadDir()
    {
        if(is_dir($this->upload_directory) == false)
        {
            if(@mkdir($this->upload_directory, 0755) == false)
            {
                throw new Exception($this->upload_directory . " 디렉토리를 생성하지 못하였습니다. 퍼미션을 확인하시기 바랍니다.");
            }
        }
    }

    private function _mkUploadSubDir()
    {
        if(is_writable($this->upload_directory) == false)
        {
            throw new Exception($this->upload_directory . " 에 쓰기 권한이 없습니다. " . $this->upload_subdirectory . "디렉토리를 생성하지 못하였습니다.");
        }
        else
        {
            $uploaded_path = $this->upload_directory . "/" . $this->upload_subdirectory;

            if(is_dir($uploaded_path) == false)
            {
                if(@mkdir($uploaded_path, 0755) == false)
                {
                    throw new Exception($uploaded_path . " 디렉토리를 생성하지 못하였습니다. 퍼미션을 확인하시기 바랍니다.");
                }
            }
            else
            {
                if(is_writable($uploaded_path) == false)
                {
                    throw new Exception($uploaded_path . " 디렉토리에 쓰기 권한이 없습니다. 파일을 업로드 할 수 없습니다.");
                }
            }
        }
    }

    public function uploadedFiles()
    {
        if(is_array($this->upload_tmpFileName))
        {
            $this->_mkUploadDir();
            $this->_mkUploadSubDir();

            for($i = 0; $i < sizeof($this->upload_tmpFileName); $i++)
            {
                $uploaded_filename = $this->upload_directory . "/" . $this->upload_subdirectory . "/" . $this->upload_fileName[$i];

                if(@move_uploaded_file($this->upload_tmpFileName[$i], $uploaded_filename) == false)
                {
                    throw new Exception($uploaded_filename . " 을 저장하지 못하였습니다.");
                }
                else
                {
                    $this->upload_count += 1;
                }

                @unlink($this->upload_tmpFileName[$i]);
            }
        }
        else
        {
            if(is_uploaded_file($this->upload_tmpFileName))
            {
                $this->_mkUploadDir();
                $this->_mkUploadSubDir();

                $uploaded_filename = $this->upload_directory . "/" . $this->upload_subdirectory . "/" . $this->upload_fileName;

                if(@move_uploaded_file($this->upload_tmpFileName, $uploaded_filename) == false)
                {
                    throw new Exception($uploaded_filename . " 을 저장하지 못하였습니다.");
                }
                else
                {
                    $this->upload_count += 1;
                }
                @unlink($this->upload_tmpFileName);
            }
        }
    }

    // 이미지정보
    private function _getImageSize($tmp_file)
    {
        $img = @getimagesize($tmp_file);

        $img[0] = $img[0] ? $img[0] : 0;
        $img[1] = $img[1] ? $img[1] : 0;

        return $img;
    }

    // 금지 확장자명을 허용 확장자로 변경하여 파일명 지정
    private function _checkFileName($fileName)
    {
        $fileName = strtolower($fileName);

        foreach($this->denied_ext as $key => $value)
        {
            if($this->_getExtension($fileName) == trim($key))
            {
                $expFileName = explode(".", $fileName);

                for($i = 0; $i < sizeof($expFileName) - 1; $i++)
                {
                    $fname .= $expFileName[$i] . $value;
                }
                return $fname;
            }
        }
        return $fileName;
    }

    /**
     * 파일명의 빈 부분을 "_" 로 변경
     */
    private function _emptyToUnderline($fileName)
    {
        return preg_replace("/\ /i", "_", $fileName);
    }

    /**
     * 확장자 추출
     */
    private function _getExtension($fileName)
    {
        //return strtolower(substr(strrchr($fileName, "."), 1));
        $path = pathinfo($fileName);
        return $path['extension'];
    }

    /**
     * 이미지 파일이 아닌 파일이 존재한다면 에러
     */
    public function checkImageOnly()
    {
        if(is_array($this->upload_tmpFileName))
        {
            for($i = 0; $i < sizeof($this->upload_tmpFileName); $i++)
            {
                if($this->_isThisImageFile($this->upload_fileType[$i]) == false)
                {
                    throw new Exception($this->upload_fileName[$i] . " 은 이미지 파일이 아닙니다.");
                }
            }
        }
        else
        {
            if(is_uploaded_file($this->upload_tmpFileName))
            {
                if($this->_isThisImageFile($this->upload_fileType) == false)
                {
                    throw new Exception($this->upload_fileName . " 은 이미지 파일이 아닙니다.");
                }
            }
        }
    }

    /**
     * gd library information - array
     * --------------------------------------------------------------------------------
     * GD Version : string value describing the installed libgd version.
     * Freetype Support : boolean value. TRUE if Freetype Support is installed.
     * Freetype Linkage : string value describing the way in which Freetype was linked. Expected values are: 'with freetype',
                          'with TTF library', and 'with unknown library'. This element will only be defined if Freetype Support
                          evaluated to TRUE.
     * T1Lib Support : boolean value. TRUE if T1Lib support is included.
     * GIF Read Support : boolean value. TRUE if support for reading GIF images is included.
     * GIF Create Support : boolean value. TRUE if support for creating GIF images is included.
     * JPG Support : boolean value. TRUE if JPG support is included.
     * PNG Support : boolean value. TRUE if PNG support is included.
     * WBMP Support : boolean value. TRUE if WBMP support is included.
     * XBM Support : boolean value. TRUE if XBM support is included.
     * --------------------------------------------------------------------------------
     */
    public function makeThumbnailed($max_width, $max_height, $thumb_head = null)
    {
        if(extension_loaded("gd") == false)
        {
            throw new Exception("GD 라이브러리가 설치되어 있지 않습니다.");
        }
        else
        {
            $gd = @gd_info();

            if(substr_count(strtolower($gd['GD Version']), "2.") == 0)
            {
                $this->_thumbnailedOldGD($max_width, $max_height, $thumb_head);
            }
            else
            {
                $this->_thumbnailedNewGD($max_width, $max_height, $thumb_head);
            }
        }
    }

    /**
     * GD Library 1.X 버전대를 위한 섬네일 함수
     *
     * GIF 포맷을 지원하지 않음
     */
    private function _thumbnailedOldGD($max_width, $max_height, $thumb_head)
    {
        if(is_array($this->upload_tmpFileName))
        {
            $this->_mkUploadDir();
            $this->_mkUploadSubDir();

            for($i = 0; $i < sizeof($this->upload_tmpFileName); $i++)
            {
                if($this->_isThisImageFile($this->upload_fileType[$i]) == true)
                {
                    switch($this->upload_fileImageType[$i])
                    {
                        case 1 :
                            $im = @imagecreatefromgif($this->upload_tmpFileName[$i]);
                        break;
                        case 2 :
                            $im = @imagecreatefromjpeg($this->upload_tmpFileName[$i]);
                        break;
                        case 3 :
                            $im = @imagecreatefrompng($this->upload_tmpFileName[$i]);
                        break;
                    }

                    if(!$im)
                    {
                        throw new Exception("썸네일 이미지 생성 중 문제가 발생하였습니다.");
                    }
                    else
                    {
                        $sizemin = $this->_getWidthHeight($this->upload_fileWidth[$i], $this->upload_fileHeight[$i], $max_width, $max_height);

                        $small = @imagecreate($sizemin[width], $sizemin[height]);

                        @imagecolorallocate($small, 255, 255, 255);
                        @imagecopyresized($small, $im, 0, 0, 0, 0, $sizemin[width], $sizemin[height], $this->upload_fileWidth[$i], $this->upload_fileHeight[$i]);

                        $thumb_head = ($thumb_head != null) ? $thumb_head : "thumb";
                        $thumb_filename = $this->upload_directory . "/" . $this->upload_subdirectory . "/" . $this->upload_fileName[$i] . ".${thumb_head}";

                        if ($this->upload_fileImageType[$i] == 2)
                        {
                            if(@imagejpeg($small, $thumb_filename, 100) == false)
                            {
                                throw new Exception("jpg/jpeg 썸네일 이미지를 생성하지 못하였습니다.");
                            }
                        }
                        else if ($this->upload_fileImageType[$i] == 3)
                        {
                            if(@imagepng($small, $thumb_filename) == false)
                            {
                                throw new Exception("png 썸네일 이미지를 생성하지 못하였습니다.");
                            }
                        }

                        if($small != null)
                        {
                            @imagedestroy($small);
                        }
                        if($im != null)
                        {
                            @imagedestroy($im);
                        }
                    }
                }
            }
        }
        else
        {
            if(is_uploaded_file($this->upload_tmpFileName))
            {
                $this->_mkUploadDir();
                $this->_mkUploadSubDir();

                if($this->_isThisImageFile($this->upload_fileType) == true)
                {
                    switch($this->upload_fileImageType)
                    {
                        case 1 :
                            $im = @imagecreatefromgif($this->upload_tmpFileName);
                        break;
                        case 2 :
                            $im = @imagecreatefromjpeg($this->upload_tmpFileName);
                        break;
                        case 3 :
                            $im = @imagecreatefrompng($this->upload_tmpFileName);
                        break;
                    }

                    if(!$im)
                    {
                        throw new Exception("썸네일 이미지 생성 중 문제가 발생하였습니다.");
                    }
                    else
                    {
                        $sizemin = $this->_getWidthHeight($this->upload_fileWidth, $this->upload_fileHeight, $max_width, $max_height);

                        $small = @imagecreate($sizemin[width], $sizemin[height]);

                        @imagecolorallocate($small, 255, 255, 255);
                        @imagecopyresized($small, $im, 0, 0, 0, 0, $sizemin[width], $sizemin[height], $this->upload_fileWidth, $this->upload_fileHeight);

                        $thumb_head = ($thumb_head != null) ? $thumb_head : "thumb";
                        $thumb_filename = $this->upload_directory . "/" . $this->upload_subdirectory . "/" . $this->upload_fileName . ".${thumb_head}";

                        if ($this->upload_fileImageType == 2)
                        {
                            if(@imagejpeg($small, $thumb_filename, 100) == false)
                            {
                                throw new Exception("jpg/jpeg 썸네일 이미지를 생성하지 못하였습니다.");
                            }
                        }
                        else if ($this->upload_fileImageType == 3)
                        {
                            if(@imagepng($small, $thumb_filename) == false)
                            {
                                throw new Exception("png 썸네일 이미지를 생성하지 못하였습니다.");
                            }
                        }

                        if($small != null)
                        {
                            @imagedestroy($small);
                        }
                        if($im != null)
                        {
                            @imagedestroy($im);
                        }
                    }
                }
            }
        }
    }

    /**
     * GD Library 2.X 버전대를 위한 섬네일 함수
     *
     * GIF 포맷을 지원함
     */
    private function _thumbnailedNewGD($max_width, $max_height,  $thumb_head)
    {
        if(is_array($this->upload_tmpFileName))
        {
            $this->_mkUploadDir();
            $this->_mkUploadSubDir();

            for($i = 0; $i < sizeof($this->upload_tmpFileName); $i++)
            {
                if($this->_isThisImageFile($this->upload_fileType[$i]) == true)
                {
                    switch($this->upload_fileImageType[$i])
                    {
                        case 1 :
                            $im = @imagecreatefromgif($this->upload_tmpFileName[$i]);
                        break;
                        case 2 :
                            $im = @imagecreatefromjpeg($this->upload_tmpFileName[$i]);
                        break;
                        case 3 :
                            $im = @imagecreatefrompng($this->upload_tmpFileName[$i]);
                        break;
                    }

                    $sizemin = $this->_getWidthHeight($this->upload_fileWidth[$i], $this->upload_fileHeight[$i], $max_width, $max_height);

                    $small = @imagecreatetruecolor($sizemin[width], $sizemin[height]);

                    @imagecolorallocate($small, 255, 255, 255);
                    @imagecopyresampled($small, $im, 0, 0, 0, 0, $sizemin[width], $sizemin[height], $this->upload_fileWidth[$i], $this->upload_fileHeight[$i]);

                    $thumb_head = ($thumb_head != null) ? $thumb_head : "thumb";
                    $thumb_filename = $this->upload_directory . "/" . $this->upload_subdirectory . "/" . $this->upload_fileName[$i] . ".${thumb_head}";

                    if($this->upload_fileImageType[$i] == 1)
                    {
                        if(@imagegif($small, $thumb_filename) == false)
                        {
                            throw new Exception("gif 썸네일 이미지를 생성하지 못하였습니다.");
                        }
                    }
                    else if ($this->upload_fileImageType[$i] == 2)
                    {
                        if(@imagejpeg($small, $thumb_filename, 100) == false)
                        {
                            throw new Exception("jpg/jpeg 썸네일 이미지를 생성하지 못하였습니다.");
                        }
                    }
                    else if ($this->upload_fileImageType[$i] == 3)
                    {
                        if(imagepng($small, $thumb_filename) == false)
                        {
                            throw new Exception("png 썸네일 이미지를 생성하지 못하였습니다.");
                        }
                    }

                    if($small != null)
                    {
                        @imagedestroy($small);
                    }
                    if($im != null)
                    {
                        @imagedestroy($im);
                    }
                }
            }
        }
        else
        {
            if(is_uploaded_file($this->upload_tmpFileName))
            {
                $this->_mkUploadDir();
                $this->_mkUploadSubDir();

                if($this->_isThisImageFile($this->upload_fileType) == true)
                {
                    switch($this->upload_fileImageType)
                    {
                        case 1 :
                            $im = @imagecreatefromgif($this->upload_tmpFileName);
                        break;
                        case 2 :
                            $im = @imagecreatefromjpeg($this->upload_tmpFileName);
                        break;
                        case 3 :
                            $im = @imagecreatefrompng($this->upload_tmpFileName);
                        break;
                    }

                    $sizemin = $this->_getWidthHeight($this->upload_fileWidth, $this->upload_fileHeight, $max_width, $max_height);

                    $small = @imagecreatetruecolor($sizemin[width], $sizemin[height]);

                    @imagecolorallocate($small, 255, 255, 255);
                    @imagecopyresampled($small, $im, 0, 0, 0, 0, $sizemin[width], $sizemin[height], $this->upload_fileWidth, $this->upload_fileHeight);

                    $thumb_head = ($thumb_head != null) ? $thumb_head : "thumb";
                    $thumb_filename = $this->upload_directory . "/" . $this->upload_subdirectory . "/" . $this->upload_fileName . ".${thumb_head}";

                    if($this->upload_fileImageType == 1)
                    {
                        if(@imagegif($small, $thumb_filename) == false)
                        {
                            throw new Exception("gif 썸네일 이미지를 생성하지 못하였습니다.");
                        }
                    }
                    else if ($this->upload_fileImageType == 2)
                    {
                        if(@imagejpeg($small, $thumb_filename, 100) == false)
                        {
                            throw new Exception("jpg/jpeg 썸네일 이미지를 생성하지 못하였습니다.");
                        }
                    }
                    else if ($this->upload_fileImageType == 3)
                    {
                        if(imagepng($small, $thumb_filename) == false)
                        {
                            throw new Exception("png 썸네일 이미지를 생성하지 못하였습니다.");
                        }
                    }

                    if($small != null)
                    {
                        @imagedestroy($small);
                    }
                    if($im != null)
                    {
                        @imagedestroy($im);
                    }
                }
            }
        }
    }

    /**
     * 제한된 가로/세로 길이에 맞추어 원본이미지의 줄인 windth, height 값을 리턴
     * _getWidthHeight(원본이미지가로, 원본이미지세로, 제한가로, 제한세로)
     */
    private function _getWidthHeight($org_width, $org_height, $max_width, $max_height)
    {
        $img = array();

        if($org_width <= $max_width && $org_height <= $max_height)
        {
            $img[width] = $org_width;
            $img[height] = $org_height;
        }
        else
        {
            if($org_width > $org_height)
            {
                $img[width] = $max_width;
                $img[height] = ceil($org_height * $max_width / $org_width);
            }
            else if($org_width < $org_height)
            {
                $img[width] = ceil($org_width * $max_height / $org_height);
                $img[height] = $max_height;
            }
            else
            {
                $img[width] = $max_width;
                $img[height] = $max_height;
            }

            if($img[width] > $max_width)
            {
                $img[width] = $max_width;
                $img[height] = ceil($org_height * $max_width / $org_width);
            }
            if($img[height] > $max_height)
            {
                $img[width] = ceil($org_width * $max_height / $org_height);
                $img[height] = $max_height;
            }
        }
        return $img;
    }

    public function __destruct()
    {
    }
};
?>

----------------------------------------------------------------
php5 사용자를 위한 업로드 클래스 함수 입니다~

단일파일업로드,다중파일업로드,썸네일 이미지 생성 기능 등의 역할을 합니다~

기본적인 사용법은 아래와 같습니다.

try
{
    $upload = new upload("업로드_디렉토리");
    $upload->define("업로드_파일");
    // 이미지 파일만 업로드 하고자 할경우
    // $upload->checkImageOnly();
    $upload->makeThumbnailed(500, 500, "thumb_500");
    $upload->uploadedFiles();
}
catch(Exception $e)
{
    // 에러처리 구문
    exit($e->getMessage());
}


"업로드_파일" 은

<input type="file" name="attach" id="attach" size="50">

와 같은 경우 $_FILES[attach] 라고 적어주시면 됩니다.

아래와 같은 다중파일 업로드 일 경우

<input type="file" name="attach[]" id="attach" size="50">
<input type="file" name="attach[]" id="attach" size="50">
<input type="file" name="attach[]" id="attach" size="50">

도 $_FILES[attach] 까지만 적어주시면 되겠지요~

업로드 디렉토리의 경우 "/data/pds" 라고 지정을 했을 경우
data 디렉토리에 쓰기 권한이 주어져야 하며 pds 라는 디렉토리는 존재하지 않으면 생성하게 됩니다.
맨 마지막에 지정된 디렉토리는 존재하면 그 디렉토리를 사용하고, 그렇지 않을 경우 생성을 하게 되는거겠졍~
pds 라는 디렉토리를 생성 후 각각의 파일은 time() 함수로 생성되어진 디렉토리를 생성시킨 후 저장됩니다.
파일이 저장되는 실제 디렉토리는 다음과 같습니다.

"data/pds/1106528137/test.jpg"

이때

$upload->upload_directory 에는 "data/pds" 가 지정되고
$upload->upload_subdirectory 에는 "1106528137" 가 지정됩니다.

썸네일 생성기능을 포함하고 있습니다.
가로,세로 500x500 픽셀짜리 썸네일을 생성하고 싶으시면..

$upload->makeThumbnailed(500, 500);

또는

$upload->makeThumbnailed(500, 500, "thumb_500");

과 같은 방식으로 사용가능합니다.

첫번째의 경우 "원본파일명.thumb"
두번째의 경우 "원본파일명.thumb_500"

처럼 썸네일이 생성되게 됩니다.
썸네일은 파일 하나에 수개에서 수십개까지 생성이 가능합니다.
만약 파일별 썸네일을 사이즈별로 4개까지 만들고 싶을 경우

$upload = new upload("data/pds");
$upload->define($_FILES['attach']);
$upload->makeThumbnailed(100, 100, "thumb_100");
$upload->makeThumbnailed(200, 200, "thumb_200");
$upload->makeThumbnailed(300, 300, "thumb_300");
$upload->makeThumbnailed(400, 400, "thumb_400");
$upload->uploadedFiles();

처럼도 사용이 가능합니다.
만약 $_FILES['attach'] 가 다중파일 업로드의 형식이라면 한 파일당 4개의 썸네일이 생성되겠죠~
썸네일 기능은 gd 가 설치되어진 상태에서 gd 를 지원하도록 php 가 컴파일 되어져야 합니다.
gd 의 버전을 확인하여 썸네일을 생성시켜 줍니다.
gd 1.x 버전이라면 gif 의 썸네일 생성이 지원되지 않으며 2.x 버전이라면 gif 도 썸네일 생성이
가능합니다.
위의 경우 만약 "test.jpg" 라는 파일을 업로드 하였다면

data/pds/1106528137/test.jpg
data/pds/1106528137/test.jpg.thumb_100
data/pds/1106528137/test.jpg.thumb_200
data/pds/1106528137/test.jpg.thumb_300
data/pds/1106528137/test.jpg.thumb_400

처럼 원본파일 이외에 4개의 썸네일 이미지가 생성되겠죠.
썸네일 이미지는 원본 이미지의 크기를 고려해 생생되므로 이미지가 깨지지 않습니다.

업로드 후 업로드 되어진 데이터는 $upload 객체를 global 화 시켜 불러올 수 있습니다.
다만 해당 함수가 불려지기전 업로드가 진행되어진 상태라야 하겠지요~
만약 글쓰기 함수에서 업로드 정보를 가져오고 싶을 경우라면...

function writeData()
{
    global $upload;

    // 다중 파일 업로드 정보를 가져옴
    if(is_array($upload->upload_tmpFileName))
    {
        for($i = 0; $i < sizeof($upload->upload_tmpFileName); $i++)
        {
            $fileDirectory = $upload->upload_directory;
            $fileSubDirectory = $upload->upload_subdirectory;
            $fileName = $upload->upload_fileName[$i];
            $fileSize = $upload->upload_fileSize[$i];
            $fileType = $upload->upload_fileType[$i];
            $fileWidth = $upload->upload_fileWidth[$i];
            $fileHeight = $upload->upload_fileHeight[$i];
            $fileExt = $upload->upload_fileExt[$i];
        }
    }
    else
    {
        // 단일 파일 업로드 정보를 가져옴
        $fileDirectory = $upload->upload_directory;
        $fileSubDirectory = $upload->upload_subdirectory;
        $fileName = $upload->upload_fileName;
        $fileSize = $upload->upload_fileSize;
        $fileType = $upload->upload_fileType;
        $fileWidth = $upload->upload_fileWidth;
        $fileHeight = $upload->upload_fileHeight;
        $fileExt = $upload->upload_fileExt;
    }

    .......
    .......
    .......
}


처럼 $upload 객체의 값을 가져와 저장시킬 수 있습니다.


파일 업로드시 썸네일 생성 함수를 사용한다 하더라도 업로드 파일이
이미지가 아니라면 썸네일 생성 함수에서 무시하게 되므로
이미지 파일과 기타 다른 파일의 동시 업로드가 가능합니다.

만약 이미지 파일만 업로드 하고자 할 경우라면..

$upload->checkImageOnly();

를 썸네일 생성함수 이전에 불러들이면 됩니다.(앨범 자료실의 경우)

확장자 금지 기능이 포함되어 있습니다.

public $denied_ext = array
(
    "php"    => ".phps",
    "phtml"    => ".phps",
    "html"    => ".txt",
    "htm"    => ".txt",
    "inc"    => ".txt",
    "sql"    => ".txt",
    "cgi"    => ".txt",
    "pl"    => ".txt",
    "jsp"    => ".txt",
    "asp"    => ".txt",
    "phtm"    => ".txt"
);

에서 처럼

"금지확장자" => "변경할확장자"

로 지정해 주시면 파일 업로드시 확장자를 변경하여 저장하게 됩니다.
아시는 내용일테니.. 이 부분은 넘어가겠습니다. ^^;

대충 정리해보니 내용이 많아 보이지만.. 실상 별거 없습니다.
다들 아시는 내용일테니 보시면 금방 이해하시리라 믿고..

쇼핑몰 등에서 크기별 이미지를 생성하거나 할때 조금이나마 도움이 될까 해서 올려봅니다.
php5 로 제작되었지만 몇가지만 고치면 php4 버전에서도 쓸 수 있을 것 같습니다.

귀차니즘의 발동이군욥~ ㅜ.ㅡ

행복한 하루 되시기 바랍니다~ :)

'Web DEV > PHP' 카테고리의 다른 글

에디트 플러스 에서 파일마다 폴더 일치 시키기  (0) 2016.06.03
display_errors,Date 오류,error_report  (0) 2012.06.20
addslashes,stripslashes  (0) 2010.07.21
자동글쓰기 방지  (0) 2010.03.09