1 / 12
文档名称:

图片上传的一个类库的源码文库.doc

格式:doc   大小:56KB   页数:12页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

图片上传的一个类库的源码文库.doc

上传人:liangwei2005 2020/7/10 文件大小:56 KB

下载得到文件列表

图片上传的一个类库的源码文库.doc

相关文档

文档介绍

文档介绍::<imgsrc="yourPath/<%=读出的图片名%>">:if(().ToLower().IndexOf("image")<0){//非图片文件}:(@"C:\ccc\ddd\");,它的实现也很简单,可以新建一个上传类UpLoadAndSaveImage,这个类中包含三个函数UpLoadAndSave,CreateFilePath,SaveToServer。使用时调用下面的UpLoadAndSave函数就可以了,该函数第一个参数为要上传的图片数据,第二个参数为上传的虚拟路径(相对路径),第三个参数为上传图片的格式,第四个参数为上传的物理路径。在这个函数中调用CreateFilePath函数产生随机的图片名称,最后再调用SaveToServer保存图片到服务器上。publicstringUpLoadAndSave(byte[]data,refstringvirPath,stringfext,stringphysicPath){//返回文件物理地址,修改虚拟地址if(data==null||virPath==null||fext==null||physicPath==""){thrownewException("非法参数");}stringrtnValue=SaveToServer(data,fext,physicPath,);virPath+=rtnValue;physicPath+=rtnValue;returnphysicPath;}privatestringCreateFilePath(stringfext){stringfilePath="";Randomrd=newRandom();filePath+=("0000");filePath+=("00");filePath+=("00");filePath+=("00");filePath+=("00");filePath+=("00");filePath+=("00");filePath+=(99).ToString("00");filePath+="."+fext;returnfilePath;}privatestringSaveToServer(byte[]data,stringfext,stringphysicPath,intfileLen){stringfilePath=CreateFilePath(fext);stringrtnValue=filePath;filePath=(0,***@physicPath);if((filePath)){filePath=CreateFilePath(fext);rtnValue=filePath;}FileStreamfs=newFileStream(filePath,);(data,0,fileLen);();returnrtnValue;}//在其他页面调用该上传类,见下面的实例:UpLoadAndSaveImageupload=newUpLoadAndSaveImage();try{stringvirPath="UploadFiles/";stringphysicPath=(+"/"+"UploadFiles/");stringfext=;if(==0){return;}fext=(fext)