本文实例讲述了PHP实现一个按钮点击上传多个图片。分享给大家供大家参考,具体如下:
test.html 代码如下
<form action="upload.php" method="post" enctype="multipart/form-data"> <p>Pictures:<br /> <input type="file" name="pictures[]" /><br /> <input type="file" name="pictures[]" /><br /> <input type="file" name="pictures[]" /><br /> <input type="submit" name="upload" value="添加" /> </p> </form>
upload.PHP 上传代码如下
<?php $uploadfile; if($_POST['upload']=='添加'){ $dest_folder = "picture/"; //上传图片保存的路径 图片放在跟你upload.php同级的picture文件夹里 $arr=array(); //定义一个数组存放上传图片的名称方便你以后会用的,如果不用那就不写 $count=0; 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); $arr[$count]=$uploadfile; echo $arr[$count]."<br />"; $count++; } } echo "<hr/>";var_dump($arr);die; } ?>
更多关于PHP相关内容感兴趣的读者可查看本站专题