[PHP] 파일/폴더 생성과 삭제

by 민갤

PHP /

파일 File

  • 생성

bool move_uploaded_file ( string $filename , string $destination )

if(move_uploaded_file($_FILES['upfile']['tmp_name'][0], $path))
{
	$result = true;
}
else
{
	$result = false;
}

HTML form 설정

<form action="" enctype="multipart/form-data" method="post">
	<input type="file" name="upfile">
</form>
  • 삭제

bool unlink ( string $filename [, resource $context ] )

if(is_file($path))
{
	if(unlink($path))
	{
		$result = true;
	}
	else
	{
		$result = false;
	}
}

폴더 Directory

  • 생성

bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = FALSE [, resource $context ]]] )

mkdir 사용 시 umask 설정값에 따라 폴더에 부여되는 권한이 달라진다.

ex) mkdir(0757) - umask(0002) = 0755

방법1) umask를 0으로 설정한다.

int umask ([ int $mask ] )

if(!is_dir($path))
{
	umask(0);
	mkdir($path, 0757, true);
}

bool chmod ( string $filename , int $mode )

if(!is_dir($file))
{
	mkdir($path);
	chmod($path, 0757);
}
  • 삭제

bool rmdir ( string $dirname [, resource $context ] )

if(is_dir($path))
{
	if(rmdir($path))
 	{
		$result = true;
	}
 	else 
	{
		$result = false;
	}
}

Author

민갤

민갤

Back-End Developer

꾸잉꾸잉하고 웁니다.

다음글 PHP 7.2 Migraion

로그인

디코에 오신 것을 환영해요!
전문가들의 수많은 아티클 창고 🤓