Home > php教程 > php手册 > php简单实现批量上传图片的方法,

php简单实现批量上传图片的方法,

WBOY
Release: 2016-06-13 08:40:12
Original
846 people have browsed it

php简单实现批量上传图片的方法,

本文实例讲述了php简单实现批量上传图片的方法。分享给大家供大家参考,具体如下:

<&#63;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++;
}
}
&#63;>
<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>

Copy after login

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php文件操作总结》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template