하나가 아닌 여러 파일을 업로드하고 싶습니다. 단일 파일 (이미지)을 업로드하는 방법을 알고 있습니다. 여러 파일을 업로드하는 데 도움이 필요합니다. 아래에서 하나의 파일을 업로드하는 방법을 볼 수 있습니다.서버에 여러 파일 업로드
는 여기에 추가 내 HTML이다 : 나는 어떤 사람들은 이름 = "파일"로 변경 보았다
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" multiple><br>
<input type="submit" name="submit" value="Submit">
</form>
이름 에 = "[] 파일". 하지만 PHP로 업로드하는 방법을 모르겠습니다. 당신이 사용하는 경우 여기
는 PHP 코드<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
$random_digit=rand(0000,9999);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
$file_name = $_FILES["file"]["name"];
$ext = pathinfo($file_name, PATHINFO_EXTENSION); // Get the extension of a file
$new_file_name = $random_digit . '.' . $ext;
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $new_file_name);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
아, 네, 좋은 오래된 표준은 [w3fools] (http://w3fools.com) 완전히 불안하고는 w3fools 사람들이 얼마나 바보 같은 표현을 시도하는 방법에서 완전히 바보 둘 다 스크립트를 업로드 할 수 있습니다. –
[PHP 다중 파일 배열] 가능한 중복 (http://stackoverflow.com/questions/15941592/php-multiple-file-array) –
지금 여러 개의 파일을 추가 할 수 있습니다. 그러나 어쨌든 서버에 추가하기 전에 표시 할 수 있습니까? – EM10