$error)对数组循环判"/> $error)对数组循环判">

Home  >  Article  >  php教程  >  php简单文件图片批量上传程序代码

php简单文件图片批量上传程序代码

WBOY
WBOYOriginal
2016-06-13 10:14:441201browse

批量上传方法也很简单我们只要在给form时加个name=\"pictures[]\" 数组,然后再利用foreach ($_FILES[\"pictures\"][\"error\"] as $key => $error)对数组循环判断,再利用move_uploaded_file($tmp_name, $uploadfile); 实现文件上传就可以了。

html代码

 代码如下 复制代码

upload picture more once

 

Pictures:


 

 

 

php处理代码

 代码如下 复制代码

if($_POST['upload']=='Send'){ 

     $dest_folder    =  "picture/"; 

if(!file_exists($dest_folder)){ 

         mkdir($dest_folder); 

foreach ($_FILES["pictures"]["error"] as $key => $error) { 

      if ($error == UPLOAD_ERR_OK) { 

         $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; 

          $name     = $_FILES["pictures"]["name"][$key]; 

       $uploadfile = $dest_folder.$name; 

          move_uploaded_file($tmp_name, $uploadfile); 

      } 

?> 

方法相当简单我们只是把单文件上传改成了多文件上传,其它只改了二个地方一个是表单名改成php数组形式一种是上传文件地方利用foreach来对数组遍历了。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn