PHP实现一个按钮点击上传多个图片操作示例
吾爱主题
阅读:114
2021-09-28 11:15:00
评论:0
本文实例讲述了PHP实现一个按钮点击上传多个图片。分享给大家供大家参考,具体如下:
test.html 代码如下
?1 2 3 4 5 6 7 8 | < 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 上传代码如下
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <?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程序设计有所帮助。
原文链接:https://blog.csdn.net/luyaran/article/details/55094678
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。