당신이 당신이 무엇을 원하는의 기본 개념을 다루고 이동 :
<?php
$allowedTypes = array("image/jpg", "image/jpeg", "image/png");
$maxSize = 3 * 1024 * 1024; // 3Mb
$fileType = $_FILES["file"]["type"];
$fileSize = $_FILES["file"]["size"];
// check if there was an error
if ($_FILES["file"]["error"] > 0)
{
die($_FILES["file"]["error"]);
}
// check if the filetype is valid
if (!in_array($fileType, $allowedTypes))
{
die("Invalid file type: $fileType");
}
// check if the size doesn't exceed the limitations
if ($fileSize > $maxSize)
{
die("The file was too big: $fileSize");
}
$name = $_FILES["file"]["name"];
$tmpfile = $_FILES["file"]["tmp_name"];
// check if the filename is valid
if (preg_match("/[\w-]+\.(jpg|jpeg|png)$/", $name) != 1)
{
die("Invalid file name: $name");
}
// create unique name if needed
$path = "/var/www/images/" . $name;
move_uploaded_file($tmpfile, $path);
// add the filepath to mysql
mysql_connect("localhost", "username", "password");
mysql_select_db("imagedb");
mysql_query("INSERT INTO images (Location, Size) VALUES ('$path', '$size');");
?>
이것은 그것이 어떻게 행해질 수 있는지를 보여주기위한 것입니다.
당신은'file'을 업로드하고 '파일을 제한?에 대한 안전한 방법을 찾기로 무슨 뜻 이죠'특정 확장 또는로 제한 하시겠습니까? .. – luastoned
예. 사용자를 .png 또는 .jpg 파일로만 제한하십시오. – diesel
사용자가 자신의 프로필 이미지를 말하고 안전하게 이미지를 업로드 할 수있게하고 싶습니다. 나는 사용자가 내 사이트에 위협을 가하는 실행 파일이나 다른 것을 업로드하는 것을 원하지 않는다. – diesel