가능한 중복 :
How can I only allow certain filetypes on upload in php?만 허용 .JPG 및 .PNG 파일 만
어떻게 난 단지 아래의 스크립트 .JPG 이미지 나 .PNG 이미지를 허용 할 수 있습니까? 세션 사용자 이름과 일치하는 이미지 디렉토리를 mysql 테이블에 업로드합니다. 파일 형식을 제한 할 수 있습니까? 난 단지 .JPG 또는
if ($_POST['submit']) {
//get file attributes
$Name = $_FILES['myfile']['name'];
$tmp_name = $_FILES['myfile']['tmp_name'];
error_reporting(E_ERROR | E_PARSE);
if ($Name) {
$location = "avatars/$Name";
move_uploaded_file($tmp_name, $location) or die('Failed to upload picture');
$query = mysql_query("UPDATE fgusers3 SET imagelocation='$location' WHERE name='$name'") or die("Your profile image has been uploaded!");
}}
echo "Upload your image below:
<form action='profilepic.php' method='POST' enctype='multipart/form-data'>
Profile Picture: <input type='file' name='myfile'> <input type='submit' name='submit' value='upload'>
</form>";
스푸핑 확장, MIME 형식 등 여러 가지 방법이 있습니다. 업로드 된 파일을 처리 할 때는이 사실에 유의하십시오. –