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

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

html实例代码如下:

  1. <html>
  2. <head><title>upload picture more once</title></head>
  3. <body>
  4. <form action="" method="post" enctype="multipart/form-data">
  5. <p>Pictures:<br />
  6. <input type="file" name="pictures[]" /><br />
  7. <input type="file" name="pictures[]" /><br />
  8. <input type="file" name="pictures[]" /><br />
  9. <input type="submit" name="upload" value="Send" />
  10. </p>
  11. </form>
  12. </body>
  13. </html>

php处理实例代码如下:

  1. <?php
  2. if($_POST['upload']=='Send'){
  3. $dest_folder = "picture/";
  4. if(!file_exists($dest_folder)){
  5. mkdir($dest_folder);
  6. }
  7. foreach ($_FILES["pictures"]["error"] as $key => $error) {
  8. if ($error == UPLOAD_ERR_OK) {
  9. $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
  10. $name = $_FILES["pictures"]["name"][$key];
  11. $uploadfile = $dest_folder.$name;
  12. move_uploaded_file($tmp_name, $uploadfile);
  13. }
  14. }
  15. }
  16. ?>

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