PHP图片批量上传代码-PHP技术-源码之家-源码学院
【PHP】实现阿里云OSS文件上传(支持批量)

【PHP】实现阿⾥云OSS⽂件上传(⽀持批量)上传⽂件⾄阿⾥云OSS,整体逻辑是,⽂件先临时上传到本地,然后在上传到OSS,最后删除本地的临时⽂件(也可以不删,具体看⾃⼰的业务需求),具体实现流程如下:1、下载阿⾥云OSS对象上传SDK(PHP版)2、解压后,可⾃⾏修改⽬录名称,以下为本⼈项⽬实例(aliyun_oss改过之后的名称)项⽬⽬录结构如下:3、Index.php 为⽂件上传静态表单页4、do_upload.php 为⽂件处理控制页,封装的代码如下:上传⽂件相关的辅助函数可以⾃⾏封装,本⽂是为了便于展⽰,全部放在⼀个⽂件中 1 <?php2/**3 * @Class: do_upload.php4 * @Description: 控制器5 * @Date: 2019/10/166*/7header("Content-Type:text/html;charset=utf-8");8set_time_limit(0);9// error_reporting(E_ALL);10require __DIR__.'/AliyunOss.php';11if(!empty($_FILES['oss_file']) && !empty($_POST['type'])){12$file_arr = getFiles();13$AliyunOss = new AliyunOss();14 foreach ($file_arr as$file){15$res = upload_File($file,$type_name.'/'.$user_info['contact'],$user_info);16if(isset($res['fname']) && isset($res['dest']) && isset($res['file_name'])){17$result = $AliyunOss->upload_file($res['dest'],$res['fname']);18if($result){19//1、存⼊数据库此处部分变量及⼊库代码补全知道逻辑即可20$insert_time = date('Y-m-d H:i:s',time());21$fileData = array(22 'phone' => "'{$phone}'",23 'company_name' => "'{$oss_db->escape($user_info['contact'])}'",24 'insert_time' => "'{$insert_time}'",25 'file_name' => "'{$res['file_name']}'",26 'file_url' => "'{$result['oss_file']}'"27 );28$sql = "insert into `oss_file` (".implode(',', array_keys($fileData)).") values (".implode(',', array_values($fileData)).")";29$oss_db->query($sql);30if($oss_db->insert_id()){31//2、删除临时⽂件32unlink($res['dest']);33 }34 }35 }36 }37echo '上传成功';38header('Location:list.php');39die;40 }else{41echo '上传失败';42 }4344/**45 * ⽂件上传46 * @description47 * @param $file48 * @param string $path49 * @param $max_size50 * @param $allowExt51 * @return mixed52*/53function upload_File($file,$oss_dir = '',$user_info,$path = __DIR__.'/temp'){54$filename=$file['name'];55$temp_name=$file['tmp_name'];56$error=$file['error'];57$res = [];58if ($error==UPLOAD_ERR_OK) {59// if ($size>$max_size) {60 // $res['mes']=$filename."⽂件超过规定上传⼤⼩";61 // }62$ext = getExt($filename);63if (in_array($ext, array('exe'))) {64$res['mes']=$filename.'⾮法的⽂件';65 }66if (!is_uploaded_file($temp_name)) {67$res['mes']=$filename."⽂件不是通过HTTP POST ⽅法上传上传过来的";68 }6970if ($res) {71return$res;72 }7374if (!file_exists($path)) {75mkdir($path,0777,true);76chmod($path, 0777);77 }78$fname = getUniName($filename,$user_info);79$destination = $path.'/'.$fname.'.'.$ext;80if (move_uploaded_file($temp_name, $destination)) {81$res['mes'] = $filename.'上传成功';82$res['dest'] = $destination;83$res['fname'] = $oss_dir.'/'.$fname.'.'.$ext;84$res['file_name'] = $fname.'.'.$ext;85 }else{86$res['mes']=$filename."⽂件上传失败";87 }88 }else{89switch ($error) {90case '1':91$res['mes']="超过了配置⽂件上传⽂件的⼤⼩";92break;93case '2':94$res['mes']="超过表单设置上传⽂件⽂件的⼤⼩";95break;96case '3':97$res['mes']="⽂件部分被上传";98break;99case '4':100$res['mes']="没有⽂件被上传";101102break;103case '6':104$res['mes']="没有找到临时⽬录";105break;106case '7':107$res['mes']="⽂件不可写";108109break;110default:111$res['mes']="上传⽂件失败";112break;113 }114 }115116return$res;117118 }119/**120 * 获得⽂件扩展名121 * @param string $filename 上传⽂件名122 * @return string 返回扩展名123*/124function getExt($filename){125$arr=explode('.', basename($filename));126127return end($arr);128 }129/**130 * 获得⽂件唯⼀扩展名131 * @return string 经过md5后⽣成32位唯⼀的上传⽂件名132*/133function getUniName($fileName, $user_info)134 {135$new_fileName = substr($fileName,0,strrpos($fileName,'.'));136$oss_db = new data_base('10.1.51.64', 'root', 'abc@123456', 'dahua_oss');137$has_file = $oss_db->getRow("select * from `oss_file` where `phone` = '{$user_info['phone']}' and locate('{$fileName}',`file_url`)>0 ");138if ($has_file) {139$new_fileName .= '-1';140 }141return$new_fileName;142 }143144/**145 * 整理多个⽂件146 * @description147 * @return mixed148*/149function getFiles(){150$files = array();151foreach($_FILES as$file){152$fileNum=count($file['name']);153for ($i=0; $i < $fileNum; $i++) {154$files[$i]['name']=$file['name'][$i];155$files[$i]['type']=$file['type'][$i];156$files[$i]['tmp_name']=$file['tmp_name'][$i];157$files[$i]['error']=$file['error'][$i];158$files[$i]['size']=$file['size'][$i];159 }160 }161return$files;162 }163164 ?>5、AliyunOss.php OSS⽂件上传接⼝类1 <?php2/**3 * @Class: AliyunOss.php4 * @Description: 控制器5 * @Date: 2019/10/166*/7header("Content-Type:text/html;charset=utf-8");8// error_reporting(E_ALL);910if (is_file(__DIR__ . '/aliyun_oss/autoload.php')) {11require_once __DIR__ . '/aliyun_oss/autoload.php';12 }1314use OSS\OssClient;15use OSS\Core\OssException;1617// 阿⾥云主账号AccessKey拥有所有API的访问权限,风险很⾼。
人像php换衣服源码

人像php换衣服源码1. 什么是人像php换衣服源码人像php换衣服源码是一种基于PHP语言开发的应用程序,用于实现在人像照片中更换衣服的功能。
通过该源码,用户可以将指定的衣服图案或颜色应用到人像照片上,实现虚拟试衣的效果。
2. 源码实现原理人像php换衣服源码的实现原理主要包括以下几个步骤:1.图片上传:用户将包含人像的照片上传到服务器。
2.图片处理:服务器使用GD库或其他图像处理库对上传的照片进行处理,提取人像区域并进行分割。
3.衣服图案选择:用户可以从已有的衣服图案库中选择一款衣服图案或颜色。
4.衣服图案处理:服务器将选中的衣服图案或颜色与人像照片进行合成,保留人像区域并将衣服图案应用到对应位置。
5.图片输出:服务器将处理后的图片输出给用户,用户可以保存或分享处理后的照片。
3. 源码开发技术和工具人像php换衣服源码的开发通常使用以下技术和工具:•PHP:作为源码的主要开发语言,用于实现服务器端的逻辑处理和图像处理。
•GD库:作为PHP的图像处理库,用于对照片进行处理、分割和合成。
•HTML/CSS/JavaScript:用于实现用户界面和与用户的交互。
•MySQL:作为数据库,用于存储用户上传的照片和衣服图案信息。
•Apache/Nginx:作为Web服务器,用于部署和运行源码。
4. 源码开发步骤人像php换衣服源码的开发可以按照以下步骤进行:1.确定需求:明确源码的功能和用户需求,确定要实现的功能模块和界面设计。
2.数据库设计:设计数据库表结构,包括用户信息、照片信息、衣服图案信息等。
3.服务器端开发:使用PHP开发服务器端的逻辑处理和图像处理功能,包括图片上传、处理、合成和输出等。
4.前端开发:使用HTML/CSS/JavaScript开发用户界面,包括图片上传界面、衣服图案选择界面等。
5.数据库操作:使用PHP连接数据库,进行用户信息和照片信息的存储和查询。
6.测试和调试:对源码进行测试,修复bug,确保功能正常运行。
elementupload实现图片批量上传与预览(自定义上传)

elementupload实现图⽚批量上传与预览(⾃定义上传)1、⾸先实现图⽚批量上传⾸先是html代码:http-request:覆盖默认的上传⾏为,可以⾃定义上传的实现<el-form enctype="multipart/form-data"><el-form-item label=""><el-upload multiple ref="upload" :action="action" :headers="{processData:false,contentType: false}" name="file" :data="filist" list-type="picture-card" :file-list="fileList" :limit="20" :auto-upload="false" :with-credentials="true":disabled="productMainDisable" :on-progress="handleUpload" :on-preview="handlePictureCardPreview" :on-remove="handleRemove" :http-request="uploadFile" :before-upload="beforeAvatarUpload"><i class="el-icon-plus"></i><div slot="tip" class="el-upload__tip"><p>1、上传图⽚只能是JPG/PNG 格式!</p><p>2、上传图⽚⼤⼩不能超过 5MB!</p></div><!-- :on-success="weiBo" --></el-upload><el-dialog:visible.sync="dialogVisible"><img width="100%" :src="dialogImageUrl" alt=""></el-dialog></el-form-item></el-form>在data⾥⾯定义:action: Domain + '/supplier/purchase/purchasedeliver/createPurchaseSignPod', //上传图⽚地址fileList: [],filist: {uuid: '' ,//需要附带的参数},formDate: "",isbandel:false, uploadFile(file) {this.formDate.append('file', file.file);},//上传签收单uploadpicture(uuid) {console.log(uuid)this.classifyWindow = true;this.filist.uuid = uuid;},//确认上传图⽚(⾃定义上传实现)submitUpload() {var that = thisif(that.formDate){that.isbandel = true;}console.log(that.formDate)that.formDate = new FormData()that.$refs.upload.submit();that.formDate.append('uuid', that.filist.uuid);$.ajax({url: Domain + "/supplier/purchase/purchasedeliver/createPurchaseSignPod",dataType: "json",method: "POST",contentType:false,processData:false,// contentType: "multipart/form-data",data: that.formDate,success: function (ret) {if (ret.retStatus == "1") {that.$message({type: "success",message: "上传成功!"});// 调⽤列表页刷新数据⽅法that.classifyWindow = false;that.isbandel = false;that.doSearch();that.canleUpload();}},});},//取消上传canleUpload() {this.classifyWindow = false;this.$refs.upload.clearFiles();},handleUpload: function (event, file, fileList) {this.productMainDisable = true;},//查看⼤图handlePictureCardPreview: function (file) {this.dialogImageUrl = file.url;this.dialogVisible = true;},// ⽂件删除操作handleRemove: function (file, fileList) {this.fileList = [];this.fileList = fileList;},//上传图⽚之前判断图⽚⼤⼩及格式beforeAvatarUpload(file) {console.log(file)const isJPG = file.type === 'image/jpeg';const isPNG = file.type === 'image/png';const isLt2M = file.size / 1024 / 1024 / 1024 < 5;this.beforeUpload = false;if (!isJPG && !isPNG) {this.beforeUpload = true;this.$message.error('上传图⽚只能是 JPG/PNG 格式!');}if (!isLt2M) {this.beforeUpload = true;this.$message.error('上传图⽚⼤⼩不能超过 5MB!');}return (isJPG || isPNG) && isLt2M;},// 此处已注释,如果⽤这个⽅法上传就会有⼏张图⽚调⽤⼏次接⼝ weiBo: function (response, file, fileList) {if (response.retStatus != '1') {this.$message({type: 'error',message: response.retMessage,});} else {this.$message({type: "success",message: "上传成功!"})}2、实现图⽚预览<ul class="imgbox m-listtable f-pdg-20-t"><li v-for="(item,uuid) in srcList" :key="uuid"><el-imagestyle="width: 100%;":src="item.signPodPath":preview-src-list="new_arr"></el-image></li></ul>srcList: [], //⽤来循环的new_arr:[],//⽤来预览的数组//获取图⽚getImglist(){var that = this$.ajax({url: 'xxx',dataType: "json",method: "POST",data: {"uuid": utils.getQueryString("uuid")},success: function (ret) {if (ret.retStatus == "1") {that.srcList = JSON.parse(ret.retData) var arr = []let result = []that.srcList.forEach(item => { arr = item.signPodPaththat.new_arr.push(arr)})console.log(that.new_arr)}}})}。
PHP常用代码大全

PHP常用代码1、连接MYSQL数据库代码<?php$connec=mysql_connect("localhost","root","root") or die("不能连接数据库服务器:".mysql_error()); mysql_select_db("liuyanben",$connec) or die ("不能选择数据库: ".mysql_error());mysql_query("set names 'gbk'");>2、读取数据库,并实现循环输出<?php$sql="select * from liuyan order by ly_id desc";$conn=mysql_query($sql,$connec);while($rs=mysql_fetch_array($conn)){>循环的内容.........<?php}>3、如何实现分页,包括两个函数,两个调用1)两个函数<?//分页函数function genpage(&$sql,$page_size=2){global $prepage,$nextpage,$pages,$sums; //out param$page = $_GET["page"];$eachpage = $page_size;$pagesql = strstr($sql," from ");$pagesql = "select count(*) as ids ".$pagesql;$conn = mysql_query($pagesql) or die(mysql_error());if($rs = mysql_fetch_array($conn)) $sums = $rs[0];$pages = ceil(($sums-0.5)/$eachpage)-1;$pages = $pages>=0?$pages:0;$prepage = ($page>0)?$page-1:0;$nextpage = ($page<$pages)?$page+1:$pages;$startpos = $page*$eachpage;$sql .=" limit $startpos,$eachpage ";}//显示分页function showpage(){global $page,$pages,$prepage,$nextpage,$queryString; //param from genpage function$shownum =10/2;$startpage = ($page>=$shownum)?$page-$shownum:0;$endpage = ($page+$shownum<=$pages)?$page+$shownum:$pages;echo "共".($pages+1)."页: ";if($page>0)echo "<a href=$PHP_SELF?page=0$queryString>首页</a>";if($startpage>0)echo " ... <b><a href=$PHP_SELF?page=".($page-$shownum*2)."$queryString>?</a></b>";for($i=$startpage;$i<=$endpage;$i++){if($i==$page) echo " <b>[".($i+1)."]</b> ";else echo " <a href=$PHP_SELF?page=$i$queryString>".($i+1)."</a> ";}if($endpage<$pages)echo "<b><a href=$PHP_SELF?page=".($page+$shownum*2)."$queryString>?</a></b> ... ";if($page<$pages)echo "<a href=$PHP_SELF?page=$pages$queryString>尾页</a>";}//显示带分类的分页function showpage1(){$fenlei=$_GET["fenleiid"];global $page,$pages,$prepage,$nextpage,$queryString; //param from genpage function$shownum =10/2;$startpage = ($page>=$shownum)?$page-$shownum:0;$endpage = ($page+$shownum<=$pages)?$page+$shownum:$pages;echo "共".($pages+1)."页: ";if($page>0)echo "<a href=$PHP_SELF?fenleiid=$fenlei&page=0$queryString>首页</a>";if($startpage>0)echo " ... <b><a href=$PHP_SELF?fenleiid=$fenlei&page=".($page-$shownum*2)."$queryString>?</a></b>";for($i=$startpage;$i<=$endpage;$i++){if($i==$page) echo " <b>[".($i+1)."]</b> ";else echo " <a href=$PHP_SELF?fenleiid=$fenlei&page=$i$queryString>".($i+1)."</a> ";}if($endpage<$pages)echo "<b><a href=$PHP_SELF?fenleiid=$fenlei&page=".($page+$shownum*2)."$queryString>?</a></b> ... ";if($page<$pages)echo "<a href=$PHP_SELF?fenleiid=$fenlei&page=$pages$queryString>尾页</a>";}>2)两个调用第一个<?php$sql="select * from liuyan order by ly_id desc";genpage($sql); //只需要正常代码加上这一行就ok。
实用的PHP实例代码20个2篇

实用的PHP实例代码20个2篇PHP是一种广泛应用于Web开发的脚本语言,具有简单、灵活、易学的特点。
它不仅可以用来开发网站,还可以用来编写各种实用的应用程序。
在本文中,我们将为您介绍20个实用的PHP实例代码和使用场景。
第一篇:1-10个实例1. 文件上传文件上传是Web开发中常用的功能之一。
使用PHP,您可以很容易地实现文件上传功能,从而让用户能够向您的网站或应用程序上传文件。
2. 邮件发送PHP提供了发送电子邮件的功能,您可以使用PHP编写代码来发送电子邮件,例如发送注册确认邮件、找回密码邮件等。
3. 图片缩放PHP提供了强大的图像处理功能,您可以使用PHP来缩放图片,为您的网站或应用程序提供更好的用户体验。
4. 数据库连接在许多Web应用程序中,需要与数据库进行交互。
PHP提供了各种数据库连接操作,您可以使用PHP来连接各种类型的数据库,如MySQL、Oracle等。
5. 表单验证表单验证是保证用户输入数据有效和安全的重要环节。
PHP提供了丰富的表单验证函数,您可以使用PHP来验证用户提交的表单数据,例如检查邮箱格式、密码强度等。
6. 分页功能在处理大量数据时,分页功能非常有用。
使用PHP,您可以轻松地实现分页功能,让用户能够浏览和导航数据的不同页面。
7. 登录认证登录认证是保护网站或应用程序安全的重要步骤。
使用PHP,您可以编写代码来实现用户登录认证功能,例如检查用户名和密码是否匹配等。
8. 数据加密在处理敏感信息时,数据加密是非常重要的。
PHP提供了各种数据加密函数,您可以使用PHP来对敏感数据进行加密和解密。
9. 生成验证码验证码是防止机器人和恶意攻击的有效手段。
使用PHP,您可以生成随机验证码,并将其嵌入到表单中,确保只有人类用户能够提交表单。
10. 数据备份定期数据备份是保证数据安全的重要环节。
使用PHP,您可以编写脚本来自动备份数据库,确保数据的安全可靠。
第二篇:11-20个实例11. 数据导出有时候,需要将数据库中的数据导出为Excel、CSV等格式,以方便进行数据分析或其他用途。
ASP图片上传代码

ASP图片上传代码-----------------adm_up.asp-----------------代码如下:<!--#include file="conn.asp"--> '数据库连接文件<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>管理</title><style type="text/css"><!--.STYLE1 {color: #000000}body {margin-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;}--></style><script language="javascript">function checknull(){dm=document.formvar filter=/^\s*[a-zA-Z]{1}:(\\).*[\.][jpgJPGifIF]{3}\s*$/;if (!filter.test(dm.file1.value)){alert('请选择您要上传图片,格式只能上传jpg或gif图片!');dm.file1.focus();return false;}return true;}</script></head><body><table width="100%" border="0" align="left" cellpadding="0" cellspacing="0"><tr><td width="100%" height="26" align="left"><%if session("admupiccnt")="" then%><form action="adm_upc.asp" method="post" enctype="multipart/form-data" name="form" id="form" onsubmit="return checknull()"><input type="hidden" name="act" value="upload" /><input name="file1" type="file" class="wenxints_line" size="32"/><input name="submit" type="submit" value="上传图片" /></form><%else%> <input name="Pic" type="text" value="<%=session("admupiccnt")%>" size="38" readonly/> <%end if%></td></tr></table></body></html>-----------------adm_upc.asp-----------------<!--#include file="conn.asp"--> '数据库连接文件<html><head><meta http-equiv=Content-Type content="text/html;charset=gb2312"><title></title></head>< body><div id="admheader"></div><%dim upfile_5xSoft_StreamdimFilePath,FileMaxSize,FileType,fileweb,nameset,pathset,vfname UpFilePath="../upload/" '上传文件目录FileMaxSize=110000 '文件大小100kbFileType=".jpg.gif" '文件类型fileweb=""nameset =1function makefilename(fname)fname = replace(fname,"-","")fname = replace(fname," ","")fname = replace(fname,":","")fname = replace(fname,"PM","")fname = replace(fname,"AM","")fname = replace(fname,"上午","")fname = replace(fname,"下午","")randomize()makefilename=fname&(int(RND()*10000))end functiondimupload,file,formName,iCount,url,UpFilePath,TypeFlag,fname,File NameStrset upload=new upload_classiCount=0for each formName in upload.file ''列出所有上传了的文件set file=upload.file(formName) ''生成一个文件对象if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据if FileType<>"" then '如果限制了上传文件类型if Instr(FileType,GetExtendName(file.FileName)) thenTypeFlag = 1 '文件为允许的类型elseTypeFlag = 0 '文件为不允许的类型Response.write "不支持您所上传的文件类型:"Response.write GetExtendName(file.FileName)Response.write "<br>"end ifelseTypeFlag = 1 '没有限制上传文件类型end ifif file.FileSize<FileMaxSize then ''如果未超过文件大小限制if TypeFlag = 1 thenvfname = makefilename(now())if nameset = 1 thenfname = vfname & iCount & "." & GetExtendName(file.FileName)elseif nameset =2 thenfname = file.FileNameelseif nameset = 3 thenfname = vfname & iCount & file.FileNameend iffile.SaveAs Server.mappath(UpFilePath&fname) ''保存文件iCount=iCount+1' fileStr = fileStr & "<a href='"& UpFilePath&file.FileName&"' target='_blank'>查看上传的文件:<font color='red'>" & file.FileName &"</font> ("& file.FileSize &" kb)</a><br>"FileNameStr = UpFilePath&fnamesession("admupiccnt")=fnameend ifelseresponse.write "<center>文件大小超出限制,您最多可以上传100kb的文件"exit forend ifend ifset file=nothingnext'----------------------------------------------------------------------------------------------set upload=nothing ''删除此对象if iCount=0 thenresponse.write "<font color=red>错误!</font> <a href='adm_pc.asp'>返回</a>"response.endend ifsub HtmEnd(Msg)set upload=nothingend subfunction GetExtendName(FileName)dim ExtNameExtName = LCase(FileName)ExtName = right(ExtName,3)ExtName = right(ExtName,3-Instr(ExtName,"."))GetExtendName = ExtNameend functionresponse.write"<script>location.href('adm_pc.asp')</script>"Class upload_classdim Form,File,VersionPrivate Sub Class_InitializedimiStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFor mEnd,theFiledimstrDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePat h,iDivLen,mStrif Request.TotalBytes<1 then Exit Subset Form=CreateObject("Scripting.Dictionary")set File=CreateObject("Scripting.Dictionary")set upfile_5xSoft_Stream=CreateObject("Adodb.Stream") upfile_5xSoft_Stream.mode=3upfile_5xSoft_Stream.type=1upfile_5xSoft_Stream.openupfile_5xSoft_Stream.writeRequest.BinaryRead(Request.T otalBytes)vbEnter=Chr(13)&Chr(10)iDivLen=inString(1,vbEnter)+1strDiv=subString(1,iDivLen)iFormStart=iDivLeniFormEnd=inString(iformStart,strDiv)-1while iFormStart < iFormEndiStart=inString(iFormStart,"name=""")iEnd=inString(iStart+6,"""")mFormName=subString(iStart+6,iEnd-iStart-6)iFileNameStart=inString(iEnd+1,"filename=""")if iFileNameStart>0 and iFileNameStart<iFormEnd theniFileNameEnd=inString(iFileNameStart+10,"""")mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)iStart=inString(iFileNameEnd+1,vbEnter&vbEnter) iEnd=inString(iStart+4,vbEnter&strDiv)if iEnd>iStart thenmFileSize=iEnd-iStart-4elsemFileSize=0end ifset theFile=new FileInfotheFile.FileName=getFileName(mFileName) theFile.FilePath=getFilePath(mFileName) theFile.FileSize=mFileSizetheFile.FileStart=iStart+4theFile.FormName=FormNamefile.add mFormName,theFileelseiStart=inString(iEnd+1,vbEnter&vbEnter)iEnd=inString(iStart+4,vbEnter&strDiv)if iEnd>iStart thenmFormValue=subString(iStart+4,iEnd-iStart-4) elsemFormValue=""end ifform.Add mFormName,mFormValueend ifiFormStart=iformEnd+iDivLeniFormEnd=inString(iformStart,strDiv)-1wendEnd SubPrivate Function subString(theStart,theLen)dim i,c,stempupfile_5xSoft_Stream.Position=theStart-1stemp=""for i=1 to theLenif upfile_5xSoft_Stream.EOS then Exit forc=ascB(upfile_5xSoft_Stream.Read(1))If c > 127 Thenif upfile_5xSoft_Stream.EOS then Exit forstemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.R ead(1)))&ChrB(c)))i=i+1elsestemp=stemp&Chr(c)End IfNextsubString=stempEnd functionPrivate Function inString(theStart,varStr)dim i,j,bt,theLen,strInString=0Str=toByte(varStr)theLen=LenB(Str)for i=theStart to upfile_5xSoft_Stream.Size-theLenif i>upfile_5xSoft_Stream.size then exit Functionupfile_5xSoft_Stream.Position=i-1if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) thenInString=ifor j=2 to theLenif upfile_5xSoft_Stream.EOS theninString=0Exit forend ifif AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) thenInString=0Exit Forend ifnextif InString<>0 then Exit Functionend ifnextEnd FunctionPrivate Sub Class_T erminateform.RemoveAllfile.RemoveAllset form=nothingset file=nothingupfile_5xSoft_Stream.closeset upfile_5xSoft_Stream=nothingEnd SubPrivate function GetFilePath(FullPath) '获取文件路径If FullPath <> "" ThenGetFilePath = left(FullPath,InStrRev(FullPath, "\"))ElseGetFilePath = ""End IfEnd functionPrivate function GetFileName(FullPath) '获取文件名If FullPath <> "" ThenGetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)ElseGetFileName = ""End IfEnd functionPrivate function toByte(Str)dim i,iCode,c,iLow,iHightoByte=""For i=1 To Len(Str)c=mid(Str,i,1)iCode =Asc(c)If iCode<0 Then iCode = iCode + 65535If iCode>255 TheniLow = Left(Hex(Asc(c)),2)iHigh =Right(Hex(Asc(c)),2)toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh) ElsetoByte = toByte & chrB(AscB(c))End IfNextEnd functionEnd ClassClass FileInfodim FormName,FileName,FilePath,FileSize,FileStart Private Sub Class_InitializeFileName = ""FilePath = ""FileSize = 0FileStart= 0FormName = ""End SubPublic function SaveAs(FullPath)dim dr,ErrorChar,iSaveAs=1if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit functionif FileStart=0 or right(fullpath,1)="/" then exit functionset dr=CreateObject("Adodb.Stream")dr.Mode=3dr.Type=1dr.Openupfile_5xSoft_Stream.position=FileStart-1upfile_5xSoft_Stream.copyto dr,FileSizedr.SaveToFile FullPath,2dr.Closeset dr=nothingSaveAs=0end functionEnd Class%>另附:页面中嵌入上传页代码<iframe src="adm_pc.asp" frameborder="0" scrolling="No" width="400" height="24"></iframe>。
ThinkPHP5.1教程66.上传功能
<input type="file" name="image[]">
<input type="file" name="image[]"> <input type="file" name="image[]"> <input type="submit" value="确定"> </form>
public function uploads() {
66. 上传功能
学习要点: 1.上传功能
本节课我们来学习一下系统提供的上传方法,如何使用这个方法进行文件上传。
一.上传功能 1. 如果要实现上传功能,首先需要建立一个上传表单,具体如下:
<form action="http://localhost/tp5.1test3/public/upload" enctype="multipart/form-data" method="post">
//获取表单的上传数据 $files = Request::file('image'); foreach ($files as $file) {
PHP教程-文件上传
<html> <head><title>浏览上传目录</title></head> <body> <h1>浏览</h1> <?php $current_dir = './uploads/'; $dir = opendir($current_dir); echo "<p>上传目录是: $current_dir</p>"; echo '<p>上传列表:</p><ul>'; while ($file = readdir($dir)) { echo "<li>$file</li>"; } echo '</ul>'; closedir($dir); ?> </body></html>
当需要上传多个文件的情况,有两种实现的 解决方法:
使用不同的表单元素
<input type=file name=file_a>
<input type=file name=file_b>
使用数组格式的表单元素
<input type=file name=file[1]>
<input type=file name=file[2]>
创建和修改目录
mkdir -- 新建目录
bool mkdir ( string pathname [, int mode] ) 如:mkdir("/path/to/my/dir", 0700);
asp实现上传功能的源码演示(简单易懂)
asp无组件上传图片的源码分析及下载要实现图片的上传功能其实非常简单,只需要四个文件与一个文件夹即可实现。
第一个文件:Upload.asp这个文件的源代码如下:<form method="POST" name="myform" target="_self"><input type="text" id="DefaultPicUrl"><iframestyle="top:2px"ID="UploadFiles"src="upload_Photo.asp?PhotoUrlID=1"f rameborder=0 scrolling=no width="300" height="325"></iframe></form>说明:这个文件将引用一个名为upload_Photo.asp的文件也就是下面要讲的第二个文件作为框架,同时这里传递一个PhotoUrlID参数给pload_Photo.asp 这个文件的form1表单中的名为PhotoUrlID的隐藏域名,其值为1第二个文件:Upload_Photo.asp,这个文件的源代码如下:<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css"><!--BODY{BACKGROUND-COLOR: #E1F4EE;font-size:9pt}.tx1 { height: 20px;font-size: 9pt; border: 1px solid; border-color: #000000; color: #0000FF}--></style><SCRIPT language=javascript>function check(){var strFileName=document.form1.FileName.value;if (strFileName=="")alert("请选择要上传的文件");document.form1.FileName.focus();return false;{}}</SCRIPT></head><body leftmargin="0" topmargin="0"><formaction="Upfile_Photo.asp"method="post"name="form1"onSubmit="retur ncheck()"enctype="multipart/form-data"><input name="FileName" type="FILE" class="tx1" size="30"><inputtype="submit"name="Submit"value="上传"style="border:1pxdoublergb(88,88,88);font:9pt"><inputname="PhotoUrlID"type="hidden"value="<%=Clng(trim(request("PhotoUrlID")))%>"></form></body></html>说明:这个是作为第一个文件Upload.asp的框架文件,注意这里的FileName的文本框是用于接受上传成功之后图片的地址第三个文件:Upfile_Photo.asp,其源代码如下:<!--#include file="upfile_class.asp"--><%constupload_type=0'上传方法:0=无惧无组件上传类,1=FSO上传2=lyfupload,3=aspupload,4=chinaaspuploaddim upload,oFile,formName,SavePath,filename,fileExt,oFileSizedim EnableUploaddim arrUpFileTypedim ranNumdim msg,FoundErrdim PhotoUrlIDmsg=""FoundErr=falseEnableUpload=false%><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <style type="text/css"><!--BODY{BACKGROUND-COLOR: #E1F4EE;}font-size:9ptid="PhotoUrlID".tx1 {height: 20px;font-size: 9pt;border: 1px solid;border-color: #000000;color: #0000FF}--></style></head><body leftmargin="2" topmargin="5" marginwidth="0" marginheight="0" > <%if EnableUploadFile="No" thenresponse.write "系统未开放文件上传功能"elseselect case upload_typecase 0call upload_0()'使用化境无组件上传类case else'response.write "本系统未开放插件功能"'response.endend selectend if%></body></html><%sub upload_0()'使用化境无组件上传类set upload=new upfile_class ''建立上传对象upload.GetData(104857600)'取得上传数据,限制最大上传100M if upload.err > 0 then'如果出错select case upload.errcase 1response.write "请先选择你要上传的文件!"case 2response.write "你上传的文件总大小超出了最大限制(200k)"end select response.endend ifPhotoUrlID=Clng(trim(upload.form("PhotoUrlID")))if PhotoUrlID>0 thenSavePath = "UploadFiles"'存放上传文件的目录elseSavePath = "UploadFiles"'存放上传文件的目录end ifif right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)for each formName in upload.file '列出所有上传了的文件set ofile=upload.file(formName)'生成一个文件对象oFileSize=ofile.filesizeif oFileSize<100 thenmsg="请先选择你要上传的文件!"FoundErr=Trueelseselect case PhotoUrlIDcase 0if oFileSize>(MaxFileSize*1024) thenmsg="文件大小超过了限制,最大只能上传"&CStr(MaxFileSize)&"K的文件!"FoundErr=trueend ifcase 1if oFileSize>(10000*1024) thenmsg="文件大小超过了限制,最大只能上传10M的文件!"FoundErr=trueend ifend selectend iffileExt=lcase(ofile.FileExt)arrUpFileType=split("gif|jpg|bmp|png|swf|doc|rar|xls","|")'如需添加其它类型的文档请for i=0 to ubound(arrUpFileType)if fileEXT=trim(arrUpFileType(i)) thenEnableUpload=trueexit forend if在这里添加文档后缀名nextif fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" thenEnableUpload=falseif EnableUpload=false thenmsg="这种文件类型不允许上传!\n\n只允许上传这几种文件类型:"&FoundErr=trueend ifstrJS="<SCRIPT language=javascript>" & vbcrlfif FoundErr<>true thenrandomizeranNum=int(900*rnd)+100"gif|jpg|bmp|png|swf|doc|rar|xls"filename=SavePath&year(now)&month(now)&day(now)&hour(now)&minute(n ow)&second(now)&ranNum&"."&fileExtofile.SaveToFile Server.mappath(FileName)'保存文件response.write "文件上传成功!文件大小为:" & cstr(round(oFileSize/1024)) &"K"select case PhotoUrlIDcase 0strJS=strJS&"parent.document.myform.PhotoSize1.value='"cstr(round(oFileSize/ 1024)) & "';" & vbcrlfcase 1strJS=strJS&"parent.document.myform.DefaultPicUrl.value='"fileName & "';" & vbcrlfend selectstrJS=strJS & "alert('" & msg & "');" & vbcrlfstrJS=strJS & "history.go(-1);" & vbcrlfend ifstrJS=strJS & "</script>" & vbcrlfresponse.write strJSset file=nothingnextset upload=nothingend sub%>第四个文件upfile_class.asp,源代码如下<%Dim oUpFileStream'---------------------------------------------------------------------- '文件上传类Class UpFile_ClassDim Form,File,Version,ErrPrivate Sub Class_InitializeVersion = "无惧上传类Version V1.2"Err = -1End SubPrivate Sub Class_Terminate'清除变量及对像If Err < 0 ThenForm.RemoveAllSet Form = Nothing&&File.RemoveAllSet File = NothingoUpFileStream.CloseSet oUpFileStream = NothingEnd IfEnd SubPublic Sub GetData (MaxSize)'定义变量DimRequestBinData,sSpace,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfoDim iFileSize,sFilePath,sFileType,sFormValue,sFileNameDim iFindStart,iFindEndDim iFormStart,iFormEnd,sFormName'代码开始If Request.TotalBytes < 1 Then'如果没有数据上传Err = 1Exit SubEnd IfIf MaxSize > 0 Then '如果限制大小If Request.TotalBytes > MaxSize ThenErr = 2'如果上传的数据超出限制Exit SubEnd IfEnd IfSet Form = Server.CreateObject ("Scripting.Dictionary") pareMode = 1Set File = Server.CreateObject ("Scripting.Dictionary")pareMode = 1Set tStream = Server.CreateObject ("ADODB.Stream")Set oUpFileStream = Server.CreateObject ("ADODB.Stream") oUpFileStream.Type = 1oUpFileStream.Mode = 3oUpFileStream.OpenoUpFileStream.Write Request.BinaryRead (Request.TotalBytes) oUpFileStream.Position = 0RequestBinData = oUpFileStream.ReadiFormEnd = oUpFileStream.SizebCrLf = ChrB (13) & ChrB (10)'取得每个项目之间的分隔符sSpace = MidB (RequestBinData,1, InStrB (1,RequestBinData,bCrLf)-1) iStart = LenB(sSpace)iFormStart = iStart+2'分解项目DoiInfoEnd = InStrB (iFormStart,RequestBinData,bCrLf & bCrLf)+3 tStream.Type = 1tStream.Mode = 3tStream.OpenoUpFileStream.Position = iFormStartoUpFileStream.CopyTo tStream,iInfoEnd-iFormStarttStream.Position = 0tStream.Type = 2tStream.CharSet = "gb2312"sInfo = tStream.ReadText'取得表单项目名称iFormStart = InStrB (iInfoEnd,RequestBinData,sSpace)-1iFindStart = InStr (22,sInfo,"name=""",1)+6iFindEnd = InStr (iFindStart,sInfo,"""",1)sFormName = Mid(sinfo,iFindStart,iFindEnd-iFindStart)'如果是文件If InStr(45,sInfo,"filename=""",1) > 0 ThenSet oFileInfo = new FileInfo_Class'取得文件属性iFindStart = InStr (iFindEnd,sInfo,"filename=""",1)+10iFindEnd = InStr (iFindStart,sInfo,"""",1)sFileName = Mid(sinfo,iFindStart,iFindEnd-iFindStart) oFileInfo.FileName = Mid (sFileName,InStrRev (sFileName, "\")+1) oFileInfo.FilePath = Left (sFileName,InStrRev (sFileName, "\")) oFileInfo.FileExt = Mid (sFileName,InStrRev (sFileName, ".")+1) iFindStart = InStr (iFindEnd,sInfo,"Content-Type: ",1)+14 iFindEnd = InStr (iFindStart,sInfo,vbCr)oFileInfo.FileType = Mid(sinfo,iFindStart,iFindEnd-iFindStart) oFileInfo.FileStart = iInfoEndoFileInfo.FileSize = iFormStart -iInfoEnd -2oFileInfo.FormName = sFormNamefile.add sFormName,oFileInfoelse'如果是表单项目tStream.ClosetStream.Type = 1tStream.Mode = 3tStream.OpenoUpFileStream.Position = iInfoEndoUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-2 tStream.Position = 0tStream.Type = 2tStream.CharSet = "gb2312"sFormValue = tStream.ReadTextIf Form.Exists (sFormName) ThenForm (sFormName) = Form (sFormName) & ", " & sFormValue elseform.Add sFormName,sFormValueEnd IfEnd IftStream.CloseiFormStart = iFormStart+iStart+2'如果到文件尾了就退出Loop Until(iFormStart+2) >= iFormEndRequestBinData = ""Set tStream = NothingEnd SubEnd Class'------------------------------------------------------------------------------'文件属性类Class FileInfo_ClassDim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt'保存文件方法Public Function SaveToFile (Path)if lcase((right(Path,3))<>lcase(FileExt)) then '经典的上传漏洞^_^response.Write("<scriptlanguage=javascript>alert('警告:不允许上传这种文件!');</script>")response.endend ifOn Error Resume NextDim oFileStreamSet oFileStream = CreateObject ("ADODB.Stream")oFileStream.Type = 1oFileStream.Mode = 3oFileStream.OpenoUpFileStream.Position = FileStartoUpFileStream.CopyTo oFileStream,FileSizeoFileStream.SaveToFile Path,2oFileStream.CloseSet oFileStream = NothingEnd Function'取得文件数据Public Function FileDataoUpFileStream.Position = FileStartFileData = oUpFileStream.Read (FileSize)End FunctionEnd Class%>除了上面四个文件夹之外还需要一个名为UploadFiles的文件夹,注意以上的四个文件与文件夹都是放在网站根目录下,也就是同极目录下的,如果目录不同级,请修改路径,同时本程序不仅可以包括jpg,png,gif等类型的图片,还可以上传word、EXECL、记事本、RAR压缩包等,当然上传对大小是有限的,只限定在200K以内,如果超过200K将会出错.。
PHP上传文件方法及获取文件后缀名函数
functionuploadfile($type,$name,$ext,$size,$error,$tmp_name,$targetname,$upload_ dir){$MAX_SIZE = 2000000;$FILE_MIMES =array('image/pjpeg','image/jpeg','image/jpg','image/gif','image/png','image/x -png');$FILE_EXTS = array('.jpg','.gif','.png','.JPG','.GIF','.PNG');$file_path = $upload_dir.$targetname;if(!is_dir($upload_dir)){if(!mkdir($upload_dir))die("文件上传目录不存在并且无法创建文件上传目录");if(!chmod($upload_dir,0755))die("文件上传目录的权限无法设定为可读可写");}if($size>$MAX_SIZE)die("上传的文件大小超过了规定大小");if($size == 0)die("请选择上传的文件");if(!in_array($type,$FILE_MIMES) || !in_array($ext,$FILE_EXTS))die("请上传符合要求的文件类型");if(!move_uploaded_file($tmp_name, $file_p ath))die("复制文件失败,请重新上传");switch($error){case 0:echo "图片上传成功...<br/>";echo "3秒钟后自动跳转...如果没有跳转,<a href='uploadFile.php'>请点击这里</a>";return ;case 1:die("上传的文件超过了php.ini 中upload_max_files ize选项限制的值");case 2:die("上传文件的大小超过了HTML 表单中MAX_FILE_SIZE 选项指定的值");case 3:die("文件只有部分被上传");case 4:die("没有文件被上传");}}似乎PHP没有自带获取文件后缀名的函数,翻书也没找到,网上搜索也没有,就自己写了个函数,很轻松就可以获取了。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
PHP图片批量上传代码-PHP技术-源码之家-源码学院PHP图片批量上传代码2010-08-02 14:09:23 来源:源码之家站长整理【大中小】浏览: 510 次<?php$zpass='123456'; //登陆密码$zurl=''; //使用地址$zname='upimage.php'; //本页面名称functionimageWaterMark($groundImage,$waterPos=0,$waterImage="", $waterText="",$textFont=5,$textColor="#FF0000"){$isWaterImage = FALSE;$formatMsg = "暂不支持该文件格式,请用图片处理软件将图片转换为GIF、JPG、PNG格式。
";//读取水印文件if(!empty($waterImage) && file_exists($waterImage)){$isWaterImage = TRUE;$water_info = getimagesize($waterImage);$water_w = $water_info[0];//取得水印图片的宽$water_h = $water_info[1];//取得水印图片的高switch($water_info[2])//取得水印图片的格式{case 1:$water_im = imagecreatefromgif($waterImage);break;case 2:$water_im = imagecreatefromjpeg($waterImage);break;case 3:$water_im = imagecreatefrompng($waterImage);break;default:die($formatMsg);}}//读取背景图片if(!empty($groundImage) && file_exists($groundImage)){$ground_info = getimagesize($groundImage);$ground_w = $ground_info[0];//取得背景图片的宽$ground_h = $ground_info[1];//取得背景图片的高switch($ground_info[2])//取得背景图片的格式{case 1:$ground_im = imagecreatefromgif($groundImage);break;case 2:$ground_im = imagecreatefromjpeg($groundImage);break;case 3:$ground_im = imagecreatefrompng($groundImage);break;default:die($formatMsg);}}else{die("需要加水印的图片不存在!");}//水印位置if($isWaterImage)//图片水印{$w = $water_w;$h = $water_h;$label = "图片的";}else//文字水印{$temp = imagettfbbox(ceil($textFont*2.5),0,"./cour.ttf",$waterText);//取得使用 TrueType 字体的文本的范围$w = $temp[2] - $temp[6];$h = $temp[3] - $temp[7];unset($temp);$label = "文字区域";}if( ($ground_w<$w) || ($ground_h<$h) ){echo "需要加水印的图片的长度或宽度比水印".$label."还小,无法生成水印!";return;}switch($waterPos){case 0://随机$posX = rand(0,($ground_w - $w));$posY = rand(0,($ground_h - $h));break;case 1://1为顶端居左$posX = 0;$posY = 0;break;case 2://2为顶端居中$posX = ($ground_w - $w) / 2; $posY = 0;break;case 3://3为顶端居右$posX = $ground_w - $w; $posY = 0;break;case 4://4为中部居左$posX = 0;$posY = ($ground_h - $h) / 2; break;case 5://5为中部居中$posX = ($ground_w - $w) / 2; $posY = ($ground_h - $h) / 2; break;case 6://6为中部居右$posX = $ground_w - $w; $posY = ($ground_h - $h) / 2; break;case 7://7为底端居左$posX = 0;$posY = $ground_h - $h; break;case 8://8为底端居中$posX = ($ground_w - $w) / 2;$posY = $ground_h - $h;break;case 9://9为底端居右$posX = $ground_w - $w-6;$posY = $ground_h - $h-6;break;default://随机$posX = rand(0,($ground_w - $w));$posY = rand(0,($ground_h - $h));break;}//设定图像的混色模式imagealphablending($ground_im, true);if($isWaterImage)//图片水印{imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷贝水印到目标文件}else//文字水印{if( !empty($textColor) && (strlen($textColor)==7) ){$R = hexdec(substr($textColor,1,2));$G = hexdec(substr($textColor,3,2));$B = hexdec(substr($textColor,5));}else{die("水印文字颜色格式不正确!");}imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));}//生成水印后的图片@unlink($groundImage);switch($ground_info[2])//取得背景图片的格式{case 1:imagegif($ground_im,$groundImage);break;case 2:imagejpeg($ground_im,$groundImage);break;case 3:imagepng($ground_im,$groundImage);break;default:die($errorMsg);}//释放内存if(isset($water_info)) unset($water_info);if(isset($water_im)) imagedestroy($water_im);unset($ground_info);imagedestroy($ground_im);}><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>图片上传</title><style type="text/css"><!--body, table {font-family: "宋体";font-size: 14px;padding:0px;margin:0px;}--></style></head><body><table width="760" border="0" align="center"><tr><td><?php//当前时间$nowtime=time();$baseurl= $_SERVER['PHP_SELF'] ? dirname($_SERVER['PHP_SELF']) : dirname($_SERVER['SCRIPT_NAME']);$baseurl='http://'.$_SERVER['HTTP_HOST'].$baseurl;//检查是否有提交图片if(!empty($_FILES['attachfile']['name'])){//处理每个图片foreach($_FILES['attachfile']['name'] as $k=>$v){//图片名字不为空if(!empty($v)){//后缀必须是图片名if(eregi("\.(gif|jpg|jpeg|png|bmp)$",$v)){//图片不能大于8Mif($_FILES['attachfile']['size'][$k] > 8388608) jieqi_delfile($_FILES['attachfile']['tmp_name'][$k]);else{//解析图片后缀$tmpary=explode('.', $v);$postfix=$tmpary[count($tmpary)-1];$attachdir = date('Ym',$nowtime);if (!file_exists($attachdir)) jieqi_createdir($attachdir);$attachdir .= '/'.date('d',$nowtime);if (!file_exists($attachdir)) jieqi_createdir($attachdir);$runtime = explode(' ', microtime());$attachname=$attachdir.'/'.date('His',$nowtime).round($run time[0]*1000).$k.'.'.$postfix;@move_uploaded_file($_FILES['attachfile']['tmp_name'][$k], $attachname);@chmod($attachname, 0644);$url=jieqi_htmlstr($baseurl.'/'.$attachname);//打水印if ($_REQUEST["water"]) {$pic=$attachname;$wpic="xhxsw.gif";$info=getimagesize($pic);$w=$info[0];$h=$info[1];if ($h>140) {imageWaterMark($pic,1,"xhxsw.gif");}if ($h>400) {imageWaterMark($pic,7,"xhxsw.gif");}if ($h>1600) {imageWaterMark($pic,4,"xhxsw.gif");}}echo '<a href="'.$url.'" target="_blank">'.$url.'</a>';><span title="复制图片URL到剪贴板" onclick="setcopy('<?echo $url?>', '图片地址已经复制到剪贴板')">[复制]</span><br><? }}else{jieqi_delfile($_FILES['attachfile']['tmp_name'][$k]);}}}}function jieqi_htmlstr($str, $quote_style=ENT_QUOTES){$str = htmlspecialchars($str, $quote_style);$str = nl2br($str);$str = str_replace(" ", " ", $str);return $str;}// 读文件function jieqi_readfile($file_name){if (function_exists("file_get_contents")) {return file_get_contents($file_name);}else{$filenum = @fopen($file_name, "rb");@flock($filenum, LOCK_SH);$file_data = @fread($filenum, @filesize($file_name));@flock($filenum, LOCK_UN);@fclose($filenum);return $file_data;}}//写文件function jieqi_writefile($file_name, &$data, $method = "wb"){$filenum = @fopen($file_name, $method);if(!$filenum) return false;@flock($filenum, LOCK_EX);$ret = @fwrite($filenum, $data);@flock($filenum, LOCK_UN);@fclose($filenum);@chmod($file_name, 0777);return $ret;}//删除文件function jieqi_delfile($file_name){return unlink($file_name);}// 删除目录function jieqi_delfolder($dirname, $flag = true){$handle = @opendir($dirname);while ($file = @readdir($handle)) {if($file != '.' && $file != '..'){if (is_dir($dirname . DIRECTORY_SEPARATOR . $file)){jieqi_delfolder($dirname . DIRECTORY_SEPARATOR . $file, true);}else{@unlink($dirname . DIRECTORY_SEPARATOR . $file);}}}@closedir($handle);if ($flag) @rmdir($dirname);}//建立目录function jieqi_createdir($dirname, $mode=0777, $recursive = false){if (version_compare(PHP_VERSION, '5.0.0', '>=')) {return mkdir($dirname, $mode, $recursive);}if (!$recursive) {$ret=mkdir($dirname, $mode);if($ret) chmod($dirname, $mode);return $ret;}return is_dir($dirname) or (jieqi_createdir(dirname($dirname), $mode, true) and mkdir($dirname, $mode));}//检查目录是否存在,不存在尝试自动建立function jieqi_checkdir($dirname, $autocreate=0){if(is_dir($dirname)){return true;}else{if(empty($autocreate)) return false;else return jieqi_createdir($dirname);}}></td></tr></table><?if ($_GET[z]=$zpass){?><table width="760" border="0" align="center"><tr><td colspan="2" align="right"><form action="<?echo $zname?>" ><input type="submit" name="quit" value=" 退出"></form></td></tr></table><form name="frmupload" method="post" action="<?echo $zname?>?z=<?echo $zpass?>" enctype="multipart/form-data"> <table width="760" border="1" align="center"><tr><td colspan="2" align="center">图片批量上传程序</td></tr><td width="114">图片一:</td><td width="470"><input type='file' class='text' size='60' name='attachfile[]' id='attachfile[]' /></td></tr><tr><td>图片二:</td><td><input type='file' class='text' size='60' name='attachfile[]' id='attachfile[]' /></td></tr><tr><td>图片三:</td><td><input type='file' class='text' size='60' name='attachfile[]' id='attachfile[]' /></td></tr><tr><td>图片四:</td><td><input type='file' class='text' size='60' name='attachfile[]' id='attachfile[]' /></td></tr><tr><td>图片五:</td><td><input type='file' class='text' size='60' name='attachfile[]' id='attachfile[]' /></td></tr><tr><td>图片六:</td><td><input type='file' class='text' size='60' name='attachfile[]' id='attachfile[]' /></td></tr><td>图片七:</td><td><input type='file' class='text' size='60' name='attachfile[]' id='attachfile[]' /></td></tr><tr><td>图片八:</td><td><input type='file' class='text' size='60' name='attachfile[]' id='attachfile[]' /></td></tr><tr><td>图片九:</td><td><input type='file' class='text' size='60' name='attachfile[]' id='attachfile[]' /></td></tr><tr><td>图片十:</td><td><input type='file' class='text' size='60' name='attachfile[]' id='attachfile[]' /></td></tr><tr><input name="water" type="hidden" id="water" value="0" checked ></tr><tr><td> </td><td width=600><input type="submit" name="Submit" value=" 提交 "></form></td></tr></table><table width="760" border="0" align="center"><tr><td><?phpif(!empty($_REQUEST['delurl'])){foreach($_REQUEST['delurl'] as $v){if(empty($v)) continue;if(!eregi("\.(gif|jpg|jpeg|png|bmp)$",$v)){echo '<font color="red">您提交的不是图片地址:</font><a href="'.urlencode($v).'" target="_blank">'.$v.'</a><br>';}elseif(strpos($v,$baseurl) !== 0){echo '<font color="red">您提交的图片地址错误:</font><a href="'.urlencode($v).'" target="_blank">'.$v.'</a><br>';}else{$delpath=str_replace($baseurl,'.',$v);if(!file_exists($delpath)){echo '<font color="red">图片不存在:</font><a href="'.urlencode($v).'" target="_blank">'.$v.'</a><br>';}else{$ret=jieqi_delfile($delpath);if($ret) echo '<font color="blue">删除完成:</font><a href="'.urlencode($v).'" target="_blank">'.$v.'</a><br>';else echo '<font color="red">删除失败,可能权限不对:</font><a href="'.urlencode($v).'" target="_blank">'.$v.'</a><br>';}}}}></td></tr></table><script type="text/java script">function setcopy(text, alertmsg){clipboardData.setData('Text', text);alert(alertmsg);}</script><?php$b=0;$dir = './../uppic';echo "<center>已经上传的图片如下:\n<div style='width:830px'>";function view_dir($directory){$handle = opendir( $directory );while ( $file = readdir($handle) ){$bdir = $directory . '/' .$file ;if ($file <> '.' && $file <> '..' && $file <> 'Thumbs.db' && $file <> $zname && is_dir($bdir)){view_dir( $directory .'/'. $file);}else if( $file <> '.' && $file <> '..' && $file <> 'Thumbs.db' && $file <> $zname){$a = $file ;><div style='float:left;width:180px;' id=<?echo $b?> name=<?echo $b?>><a href='<?echo $directory?>/<?echo $a?>' target=_blank><?echo $a?></a><span title="复制图片URL到剪贴板" onclick="setcopy('http://<?echo $zurl?>/1/2/.<?echo $directory?>/<?echo $a?>', '图片地址已经复制到剪贴板')">[复制]</span></div><? $b=$b+1;}}closedir( $handle );}view_dir($dir);><form name="frmdelete" action="<?echo $zname?>?z=<?echo $zpass?>" method="post"><table width="760" border="1" align="center"cellpadding="3"><tr><td colspan="2" align="center">删除图片</td></tr><tr><td width="114">图片网址一:</td><td width="470"><input name="delurl[]" id="delurl[]" type="text" size="60"></td></tr><tr><td>图片网址二:</td><td><input name="delurl[]" id="delurl[]" type="text" size="60"></td></tr><tr><td>图片网址三:</td><td><input name="delurl[]" id="delurl[]" type="text" size="60"></td></tr><tr><td>图片网址四:</td><td><input name="delurl[]" id="delurl[]" type="text" size="60"></td></tr><tr><td>图片网址五:</td><td><input name="delurl[]" id="delurl[]" type="text" size="60"></td></tr><tr><td>图片网址六:</td><td><input name="delurl[]" id="delurl[]" type="text" size="60"></td></tr><tr><td>图片网址七:</td><td><input name="delurl[]" id="delurl[]" type="text" size="60"></td></tr><tr><td>图片网址八:</td><td><input name="delurl[]" id="delurl[]" type="text" size="60"></td></tr><tr><td>图片网址九:</td><td><input name="delurl[]" id="delurl[]" type="text" size="60"></td></tr><tr><td>图片网址十:</td><td><input name="delurl[]" id="delurl[]" type="text" size="60"></td></tr><tr><td></td><td><input type="submit" name="Submit2" value=" 删除"></td></tr></table></form><?}else{?><br><br><br><center>请输入密码:<form action="<?echo $zname?>" method="get"><input type=password name=z size=12><input type=submit value=" 提交 "></form><?}?></body></html>。