FileUpload1预览上传时的图片
<form name="form1" action="" method="post" enctype="MULTIPART-DATA">
<input type="file" id="filepath" name="filepath"/>
<input type="button" value="预览" onclick="yulan()">
<input type="submit" value="上传">
<br><br>
<img id="img" name="img" width="50" height="50">
</from>
<script>
function yulan() {
document.form1.img.src=document.form1.filepath.value;
}
</script>
用fileupload上传图片,怎么获取上传后图片的相对路径
你上传时不是通过获取过图片保存路径的绝对路径吗,比如这样:
String?path?=?this.getServletContext().getRealPath("/data/userfile/image");??//文件保存路径
然后你只需要把图片的文件名再保存在数据库中,在显示页面直接使用相对路径来指向图片文件即可,“相对路径+文件名”,比如:
<br>照片:<img?src=data/userfile/image/<jsp:getProperty?name="loginedInform"?property="pic"?/>?width=100?height=100></img>
怎么样安装fileupload控件
首先得注册这个控件。
单击Windows的“开始”菜单,选择“运行”命令,在打开的对话框中输入以下命令:
regsvr32 ------------此时控件的文件名必须包含完整的文件路径。
,
用FileUpload控件怎么实现多图片上传
FileUpload实现单图片上传,如果想多图片上传,你试试这个:
<tr>
<td align="right" valign=&">
试卷照片:
</td>
<td align="left">
<div id="_container">
<input id="File1" type="file" name="File" runat="server" size="10" />
</div>
</td>
<td align="left" valign="bottom">
<input type="button" value="添加" onclick="addFile()" />
</td>
</tr>
addFile()源码:
//多文件上传,动态生成多个上传控件
function addFile() {
var div = document.createElement("div");
var f = document.createElement("input");
f.setAttribute("type", "file");
f.setAttribute("name", "file");
f.setAttribute("size", "10");
div.appendChild(f);
document.getElementById("_container").appendChild(div);
}
后台页面调用:
#region 上传添加图片的方法
/// <summary>
/// 上传添加图片的方法
/// </summary>
/// <param name="nId">关联id</param>
private static void UploadAndAddPicTures(int nId)
{
LMS.BLL.TRAIN_Pictrue PictrueBLL = new LMS.BLL.TRAIN_Pictrue();
List<LMS.Model.TRAIN_Pictrue> list = new List<LMS.Model.TRAIN_Pictrue>();
//遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files;
for (int iFile = 0; iFile < files.Count; iFile++)
{
//检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName.ToLower() != "")
{
LMS.Model.TRAIN_Pictrue Pictrue = new LMS.Model.TRAIN_Pictrue();
string scurTypeName = fileName.Substring(fileName.LastIndexOf("."));
//初始化原图物理路径
string sGuid_phy = Guid.NewGuid().ToString();
string sUrl_phy = ConfigurationManager.AppSettings["PhysicsObjectPath"].ToString() + sGuid_phy + scurTypeName;
//初始化缩略图物理路径
string sGuid_web = Guid.NewGuid().ToString();
string sUrl_web = ConfigurationManager.AppSettings["PhysicsObjectPath"].ToString() + sGuid_web + scurTypeName;
postedFile.SaveAs(sUrl_phy);//保存原图
PTImage.ZoomAuto(postedFile, sUrl_web, 100, 100, "", "");//生成缩略图,并保存
//保存原图虚拟路径到数据库
Pictrue.path = ConfigurationManager.AppSettings["WebObjectPath"].ToString() + sGuid_phy + scurTypeName;
//保存缩略图虚拟路径到数据库
Pictrue.shrinkpath = ConfigurationManager.AppSettings["WebObjectPath"].ToString() + sGuid_web + scurTypeName;
Pictrue.parid = nId;
Pictrue.tables = "TRAIN_Hotel_MonthExam";
list.Add(Pictrue);
}
}
PictrueBLL.Add(list);
}
#endregion
希望对你有帮助!
使用FileUpload如何读取路径?
读取路径? 你是指怎么个读取。
FileUpload是不允许动态读取路径的 ,貌似只能通过后面的浏览添加路径,你想想,假设如果可以动态读取路径的话。
那好 ,我就给他动态读取一个“C:”。
那会是什么结果,哇,所有c盘东西就全部被上传上去了,多么可怕的一件事。
我想盗取你的东西,随便写一个带FileUpload控件的程序,暗地里上传你的c盘东西,我岂不是赚大发了。
是吧,其实微软早就料到这一点了 ,果断的不允许FileUpload读取路径,安全嘛