-1

我试图将多张图片上传到我的服务器,如果上传一张图片,我有以下工作,只是我不确定下一步要去哪里?

我有一个提交 3 张图片的 POST 表单,以下仅上传第一张,我需要为每张图片创建一个 while 循环吗?

到目前为止,我已经写...

    $allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . date('U')."-".$_FILES["file"]["name"]);  // add a unique string to the uploaded filename so that it is unique.
      echo "Stored in: " . "upload/" . date('U')."-".$_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";

}

谁能看到我哪里出错了?

4

1 回答 1

0

如果你想使用你的脚本,你可以这样做:

for($i = 0; $i < 3; $i++) {
 $aFile = $_FILES['file'][$i];

 // your code ($_FILES['file']['tmp_name'] should be addressed like $aFile['tmp_name'] and so on..
}
于 2012-12-18T14:52:01.033 回答