>  기사  >  백엔드 개발  >  PHP는 html5를 사용하여 여러 파일 업로드 예제를 구현합니다.

PHP는 html5를 사용하여 여러 파일 업로드 예제를 구현합니다.

高洛峰
高洛峰원래의
2017-01-14 14:08:361622검색

먼저 HTML5의 파일의 다중 속성을 소개하겠습니다.

정의 및 사용법

다중 속성은 입력 필드에서 여러 값을 선택할 수 있음을 지정합니다. 이 속성을 사용하면 필드에 여러 값을 사용할 수 있습니다.

예:

<form action="demo_form.asp" method="get">
 Select images: <input type="file" name="img" multiple="multiple" />
 <input type="submit" />
</form>

위 예의 입력 파일은 여러 파일 업로드 필드를 허용할 수 있습니다.

html5의 파일 다중 속성을 이해한 후, html5를 사용하여 여러 파일을 업로드하는 방법을 설명하겠습니다.

예제 코드:

html:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<form action="my_parser.php" method="post" enctype="multipart/form-data">
 <p><input name="upload[]" type="file" multiple="multiple" /></p>
 <input type="submit" value="Upload all files">
</form>
</body>
</html>

php 코드:

for($i=0; $i<count($_FILES[&#39;upload&#39;][&#39;name&#39;]); $i++) {
 //Get the temp file path
 $tmpFilePath = $_FILES[&#39;upload&#39;][&#39;tmp_name&#39;][$i];
 
 //Make sure we have a filepath
 if ($tmpFilePath != ""){
  //Setup our new file path
  $newFilePath = "./uploadFiles/" . $_FILES[&#39;upload&#39;][&#39;name&#39;][$i];
 
  //Upload the file into the temp dir
  if(move_uploaded_file($tmpFilePath, $newFilePath)) {
 
   //Handle other code here
 
  }
 }
}

읽어주셔서 감사합니다. 도움이 되기를 바랍니다. 이 사이트를 지원해 주셔서 감사합니다!

여러 파일 업로드 예제를 구현하기 위해 html5를 사용하는 더 많은 PHP 관련 기사를 보려면 PHP 중국어 웹사이트에 주목하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.