Posted in PHP onMay 09, 2016
本文实例讲述了php简单实现批量上传图片的方法。分享给大家供大家参考,具体如下:
<?php function upload_multi($path,$photo,$i){ $uploaddir = './'.$path;//文件存放目录 if(!file_exists($uploaddir))//如果目录不存在就新建 $uploaddir=mkdir($uploaddir); $piece = explode('.',$photo['name'][$i]); $uploadfile = $uploaddir . '/'.md5($piece[0]).'.'.$piece[1]; $result = move_uploaded_file($photo['tmp_name'][$i], $uploadfile); if(!$result){ exit('上传失败'); } return basename($uploadfile); } if($_POST['tijiao']){ extract($_POST); $i=0; foreach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { upload_multi($email,$_FILES["pictures"],$i); } $i++; } } ?> <script language="javascript"> function go_up(){ document.getElementById('new_up').innerHTML+='<input type="file" name="pictures[]" /><br>'; } </script> <form action="index.php" method="post" enctype="multipart/form-data"> <p>多图片上传</p><br> <input type="file" name="pictures[]" /><br> <div id="new_up"></div> <input type="button"" name="add_img" value="新增上传" onclick="go_up()"/><br> <input type="submit" value="Send" name="tijiao"/><br> </form>
希望本文所述对大家PHP程序设计有所帮助。
php简单实现批量上传图片的方法
- Author -
果冻声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@