파일 업로드 (중복처리) > php

본문 바로가기
사이트 내 전체검색

php

파일 업로드 (중복처리)

페이지 정보

작성자 서방님 댓글 0건 조회 163회 작성일 11-10-31 18:05

본문

*up_process.php 파일 --------------------------------------------------------------
  $UpFile = $HTTP_POST_FILES["ImageFile"][name];
  if($UpFile) // 업로드할 화일이 있는지 확인
  {
    $FileName = GetUniqFileName($UpFile, $SavePath); // 같은 화일 이름이 있는지 검사
    move_uploaded_file($HTTP_POST_FILES["ImageFile"][tmp_name],"$SavePath$FileName"); // 화일을 업로드 위치에 저장
  }
------------------------------------------------------------------------------------



*GetUniqFileName 함수 --------------------------------------------------------------
function GetUniqFileName($FN, $PN)
{
  $FileExt = substr(strrchr($FN, "."), 1); // 확장자 추출
  $FileName = substr($FN, 0, strlen($FN) - strlen($FileExt) - 1); // 화일명 추출

  $ret = "$FileName.$FileExt";
  while(file_exists($PN.$ret)) // 화일명이 중복되지 않을때 까지 반복
  {
    $FileCnt++;
    $ret = $FileName."_".$FileCnt.".".$FileExt; // 화일명뒤에 (_1 ~ n)의 값을 붙여서....
  }

  return($ret); // 중복되지 않는 화일명 리턴
}
------------------------------------------------------------------------------------

댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
5
어제
58
최대
1,347
전체
153,769
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.