多图片上传

时间:2016-01-11 11:18:13

标签: php image-uploading

我正在学习PHP而无法找到使其工作的方法。我是否编写了正确的代码来上传多张图片?

我想不出为什么这应该是错的原因。

$imageName = mysql_real_escape_string($_FILES["image, drie1, drie2, drie3, add, strip"]["name"]);    
$imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));    
$imageType = mysql_real_escape_string($_FILES["image, drie1, drie2, drie3, add, strip"]["type"]);

2 个答案:

答案 0 :(得分:0)

<强> HTML

<form action="file-upload.php" method="post" enctype="multipart/form-data">
  Send these files:<br />
  <input name="userfile[]" type="file" /><br />
  <input name="userfile[]" type="file" /><br />
  <input type="submit" value="Send files" />
</form>

PHP file-upload.php

var_dump($_FILES);

这将显示上传文件的信息

您可以在输入中添加accept属性,以通过扩展来限制允许的文件类型

答案 1 :(得分:0)

<强> HTML

<form action="upload.php" method="post" enctype="multipart/form-data">
     <input type="file" name="image_file[]" multiple=""> /* multiple tag is used to upload multiple files */
     <input type="submit" name="Submit" value="Submit" />
</form>

<强>腓

<?php
foreach($_FILES["image_file"]["name"] as $key => $value)
{
    $name = $value;
    $tmp_name = $_FILES["image_file"]["tmp_name"][$key];
    $type = $_FILES["image_file"]["type"][$key];

    echo $name." , ".$tmp_name." , ".$type."\n";
}
?>