MVC上传图片

<td rowspan="8"> 图片为:
<input type="hidden" name="img_url" id="img_url" value="@Model.img_url"/>
<img id="img_head1" style="height:200px; width:300px; @(Model.img_url == "" ? "display:none;" : "")" src="@(AppSettingGetValue.getFileServices() + "platformContent/TuWen/" + Model.img_url)"/><br />
<input type="file" name="fileImgUrl" id="fileToUpload1" multiple="multiple" onchange="fileSelected(1);" />
<a id="uploadFile1" style="display: none" href="#" class="easyui-linkbutton" data-options="iconCls:‘icon-save‘" onclick="uploadFile(1)">上传</a>
</td>

JQuery控制图片上传

function fileSelected(itype) {
$("#uploadFile" + itype).show();
}

var uploadtype = 0;
function uploadFile(itype) {
uploadtype = itype;
var fd = new FormData();
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", uploadComplete, false);
fd.append("fileToUpload", document.getElementById(‘fileToUpload‘ + itype).files[0]);
if (itype == 0) fd.append("UpLoadAdress", "platformContent\\TuWen\\");
else fd.append("UpLoadAdress", "platformContent\\TuWen\\");
xhr.open("POST", "@Url.Content("~/Common/UploadFile")");
xhr.send(fd);
}

function uploadComplete(evt) {

/* 服务器返回数据 */
var message = evt.target.responseText;
if (uploadtype == 0) {
$("#img_head").show();
$("#img_head").attr("src", "@(BBAdmin.Common.AppSettingGetValue.getFileServices())platformContent/TuWen/" + message);

if ($("#fileToUpload" + uploadtype).val() == "") {
$.message.alert("提示", "二维码上传成功!", "info");
}
else {
$("#fileToUpload" + uploadtype).val("");
}
}
if (uploadtype == 1) {
$("#img_head1").show();
$("#img_url").val(message);
$("#img_head1").attr("src", "@(BBAdmin.Common.AppSettingGetValue.getFileServices())platformContent/TuWen/" + message);
//$("#img_url").val($("#img_head1").attr("src"));

if ($("#fileToUpload1" + uploadtype).val() == "") {
$.messager.alert("提示", "头像上传成功!", "info");
}
else {
$("#fileToUpload1" + uploadtype).val("");
}
}
}

时间: 2024-08-07 02:15:58

MVC上传图片的相关文章

Spring MVC 上传图片无刷新预览

Spring Mvc 上传图片 我早期写在了 360图书馆 ,就不移过来了. 地址http://www.360doc.com/content/14/1226/11/17181183_435868225.shtml 无刷新上传 jsp页面代码.使用的是ajaxFileUpload插件. 先简单介绍一下ajaxFileUpload ,这个插件仅7KB .用起来也特别简单. 如果不是用在特别复杂的地方上应该不会出现什么bug 代码如下: HTML代码: 1 <input type="file&q

Asp.Net MVC上传图片

mvc上传图片 [HttpPost] public JsonResult Upload() { if (Request.Files.Count > 0) { if (Request.Files.Count == 1) { HttpPostedFileBase file = Request.Files[0]; if (file.ContentLength > 0) { string title = string.Empty; title = DateTime.Now.ToString("

利用Spring MVC 上传图片文件

本文转自:http://amcucn.iteye.com/blog/264457.感谢作者 近日在工作当中,需要用到上传图片的功能,然而自己平时学习的时候只会使用struts的上传功能,但因为项目并没有使用struts,而是spring mvc ,最后不得不另寻它路.通过google和百度,看到了一些相关的介绍.经过自己的偿试,最终搞定利用spring mvc 上传文件的功能,完成图片的上传.如果只是为了上传图片,可以通过限制扩展名的形式达到目的.下面给出关键的代码部分. 关于spring的配置

spring mvc上传图片

1.需要commons-fileupload.jar commons-io.jar 2.需要在springmvc.xml中 配置存放静态资源的路径,对图片等静态资源放行 <mvc:resources location="/static/" mapping="/static/**"/> 3.图片上传页面 <form action="/springmvc1/upload" method="post" enctyp

asp.net mvc 上传图片 摘自mvc 高级编程第311页

Image Uploads I am going to complete the SportsStore user experience with something a little more sophisticated: I will add the ability for the administrator to upload product images and store them in the database so that they are displayed in the pr

mvc 上传图片 web 上传图片+ 预览

源码地址: http://pan.baidu.com/s/1kTtQzpt 使用 ajaxFileUpload  上传图片. 效果图

mvc上传图片预览,支持多图上传

@using (Html.BeginForm("Index_load", "Index_", new { }, FormMethod.Post, new { @id = "form0", @class = "form-horizontal", @enctype = "multipart/form-data" })) {     <div>           <input type=&qu

kindeditor编辑器上传图片

使用的是asp.net MVC 上传图片. 1.下载Kindeditor的对应的包 2.html页面 @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>UploadByKindeditor</title> <script

FT项目开发技术点(二)

1.mybatis二级缓存,指的的是将数据缓存,而非对象,而非获得的list.缓存将数据库中的数据,是数据,缓存到内存中.之后将数据每次重新加载到list中,所以每次生成的list对象都是不同的,list.hashcode()都不同. 开启二级缓存 1).  在核心配置文件SqlMapConfig.xml中加入以下内容(开启二级缓存总开关): cacheEnabled设置为 true 2).在映射文件中,加入以下内容,开启二级缓存: 3).pojo实现序列化 由于二级缓存的数据不一定都是存储到内