在php中获取选定图像的详细信息

在php中获取选定图像的详细信息,php,html,performance,multi-upload,Php,Html,Performance,Multi Upload,我正在使用HTML5JS。为什么上载多个图像时(PHP:print\r($\u FILES['upimg']['name']))的结果只显示最后选定图像的详细信息 例如:(我选择了以下图像名称) 111111.gif 2222.gif 333333.gif 仅PHP代码上次选择的图像显示:333333.gif 但我想展示所有图片的细节 我该怎么办 演示: 完整代码: <!doctype html> <html> <head> <?php if($

我正在使用HTML5JS。为什么上载多个图像时(PHP:
print\r($\u FILES['upimg']['name'])
)的结果只显示最后选定图像的详细信息

例如:(我选择了以下图像名称)

111111.gif

2222.gif

333333.gif

仅PHP代码上次选择的图像显示:
333333.gif

但我想展示所有图片的细节

我该怎么办

演示:

完整代码:

<!doctype html>
<html>
<head>
    <?php
if($_FILES){
    echo '<pre>';
    print_r($_FILES['upimg']['name']);
    
        //for($i=0; $i<count($_FILES['name']); $i++){
            //if ($_FILES['error'][$i] == 0) {
                ////do your stuff here, each image is at $_FILES['tmp_name'][$i]
            //}
        //}
    }
?>
  <title>file input click() demo</title>
  <script type="text/javascript">
    function doClick() {
      var el = document.getElementById("fileElem");
      if (el) {
        el.click();
      }
    }
    function handleFiles(files) {
      var d = document.getElementById("fileList");
      if (!files.length) {
        d.innerHTML = "<p>No files selected!</p>";
      } else {
        var list = document.createElement("ul");
        d.appendChild(list);
        for (var i=0; i < files.length; i++) {
          var li = document.createElement("li");
          list.appendChild(li);
          
          var img = document.createElement("img");
          img.src = window.URL.createObjectURL(files[i]);;
          img.height = 60;
          img.onload = function() {
            window.URL.revokeObjectURL(this.src);
          }
          li.appendChild(img);
          
          var info = document.createElement("span");
          info.innerHTML = files[i].name + ": " + files[i].size + " bytes";
          li.appendChild(info);
        }
      }
    }
  </script>
</head>
<body>
  <p>This is a demo of calling <code>click()</code> on a form's file picker.
  Note that the file input element is actually hidden here, so the
  user doesn't have to see the path to the selected file.</p>
      <a href="javascript:doClick()">Select some files</a>
  <div id="fileList">
    <p>No files selected!</p>
  </div>
  <form action="#" method="post" enctype="multipart/form-data">
    <input name="upimg[]" type="file" id="fileElem" multiple accept="image/*" style="display:none" onchange="handleFiles(this.files)">
        <input type="submit" value="Click to see the result">
  </form>
</body>
</html>

我认为您的逻辑是错误的,您使用HTML5,但不通过AJAX上传图像,您使用表单实现此方法

Miltiple只是HTML5,如果没有AJAX,就无法用于PHP


我创建了类似的插件,您可以查看:

尝试将其包装在for循环中,有点像您注释掉的代码

myElement.width = (parentElement.width/100)*40
if(isset($\u文件[“upimg”][“name”])){

对于($i=0;$i为什么不在任何.parent div之前使用
标记

当然,对于宽度比,您可以使用jquery来实现


不确定你做错了什么,这段代码对我来说很有用,但我使用的是类似@d.danailov所描述的AJAX
myElement.width = (parentElement.width/100)*40