在用uploadify的时候遇到一个问题.
A页面代码:<table width="100%" border="0" cellspacing="0" cellpadding="0" class="TableBorder">
<tr>
<td style=" width:100px;">名称:</td>
<td>
<asp:TextBox ID="txtName" runat="server" Width="300"></asp:TextBox></td>
</tr>
<tr>
<td valign="top">上传图片:</td>
<td>
<input type="file" name="file_upload_1" id="file_upload_1" />
<div id="cp"></div>
</td>
</tr>
</table>
<asp:Button ID="bntA" runat="server" onclick="bntA_Click" Text="添加信息" />
<script type="text/javascript">
$(function () {
$("#file_upload_1").uploadify({
'buttonText': 'select...',
height: 20,
swf: '/images/uploadify.swf',
uploader: 'upload.aspx',
});
});
</script>A.aspx是一个表单,点击按钮提交.upload.aspx是处理上传图片.会把上传的图片重命名为一个唯一标识的乱数名称.比如:201282111234.jpg现在问题是:在A.aspx中,因为我要取得上传的图片的重命名名称来提交到数据库,所以,我需要取得upload.aspx上传的图片的重命名名称(或者上传图片的全路径). 像上面的201282111234.jpg 这个是需要取得的.我如何做?谢谢
A页面代码:<table width="100%" border="0" cellspacing="0" cellpadding="0" class="TableBorder">
<tr>
<td style=" width:100px;">名称:</td>
<td>
<asp:TextBox ID="txtName" runat="server" Width="300"></asp:TextBox></td>
</tr>
<tr>
<td valign="top">上传图片:</td>
<td>
<input type="file" name="file_upload_1" id="file_upload_1" />
<div id="cp"></div>
</td>
</tr>
</table>
<asp:Button ID="bntA" runat="server" onclick="bntA_Click" Text="添加信息" />
<script type="text/javascript">
$(function () {
$("#file_upload_1").uploadify({
'buttonText': 'select...',
height: 20,
swf: '/images/uploadify.swf',
uploader: 'upload.aspx',
});
});
</script>A.aspx是一个表单,点击按钮提交.upload.aspx是处理上传图片.会把上传的图片重命名为一个唯一标识的乱数名称.比如:201282111234.jpg现在问题是:在A.aspx中,因为我要取得上传的图片的重命名名称来提交到数据库,所以,我需要取得upload.aspx上传的图片的重命名名称(或者上传图片的全路径). 像上面的201282111234.jpg 这个是需要取得的.我如何做?谢谢
解决方案 »
- 理论课 MVC和三层的区别!详细说出!
- windows 2008 + mvc4 + .net framework 4.5 无法运行网站。。
- 给gridview添加选择按钮
- 用了url重写出现的问题?
- 加上查询条后和排序后,变慢了
- 在ASP.NET中如何直接创建ANSI类型的文本文件?
- 试图运行项目时出错:无法在web服务器上启动项目
- 工程中的系统常量的定义问题,给个好的意见!
- 怎样.net 调用exe文件,并且把执行的结果固定在网页的某个位置
- 能判断当前节点在第几层吗???
- 同一个页面,多个gridview控件显示数据问题
- .net StreamReader.ReadToEnd()方法在读取internet资源时会被阻塞的解决方法
$(document).ready(function () {
var num;
$("#uploadify").uploadify({
'uploader': '/js/ui/uploadify/images/uploadify.swf',
'script': '/ajax/ProductPic.ashx',
'scriptData': { userName: $("#hidUser").val(), levelID: $("#hidLevelID").val(), tag: Math.random() },
'method': 'get',
'cancelImg': '/js/ui/uploadify/images/cancel.png',
'queueSizeLimit': 5,
'maxSize': 1024 * 1024,
'fileExt': '*.jpg;*.gif;*.bmp;*.png',
'fileDesc': '*.jpg;*.gif;*.bmp;*.png',
'folder': '/upload/Picture',
'queueID': 'fileQueue',
'auto': false,
'multi': true,
'rollover': false,
onAllComplete: function (event, data) {
location.href = "WorksPictureUpload.aspx";
}
});
});
HttpPostedFile file = context.Request.Files["Filedata"];
string fileName = file.FileName;
string fileType = fileName.Substring(fileName.LastIndexOf("."));
string saveFolder = DateTime.Now.ToString("yyyyMM");
fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString() + fileType;
string uploadPath =
HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\\";
HttpPostedFile file = context.Request.Files["file"];
if (file != null)
{
if (id != 0)
{
try
{
Image i = Image.FromStream(file.InputStream);//判断是否是图片,不是会引发异常
byte[] imgDate = rarImage(i, 800, 1280, 80);//图片大小自动缩放
string ids = id.ToString("X8");
string uploadPath = HttpContext.Current.Server.MapPath(context.Request["folder"]) + "\\" + ids.Substring(0, 5) + "\\";
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
string fn = uploadPath + ids.Substring(5, 3) + ".jpg";
File.WriteAllBytes(fn, imgDate);
context.Response.Write(fn);// 传回文件名
}
catch
{
context.Response.Write("0");
}
}
else
{
context.Response.Write("0");
}
return;
}下面data返回的就是传回的文件名 onUploadSuccess: function (file, data, response) {
alert("file=" + file.name + "\n" + "data=" + data + "\n" + "response=" + response + "\n");
},
Argumentsfile
The file object that was successfully uploadeddata
The data that was returned by the server-side script (anything that was echoed by the file)response
The response returned by the server—true on success or false if no response. If false is returned, after the successTimeout option expires, a response of true is assumed.
'scriptData': { userName: $("#hidUser").val(), levelID: $("#hidLevelID").val(), tag: Math.random() },这个是你需要什么参数,就从本页面获取,再传到你跳转的页面中去。
明白?
$("#u1").val($("#u1").val()+data+'|');
}在A.aspx.cs里这样获取值. string u1=Request.Form["u1"]);
这样写测试了是可行的.但是总感觉有点别扭. jquery只懂一点. 像这样情况(在a页面获取b页面返回的值)标准的做法是怎样的?谢谢!