| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2651 人关注过本帖
标题:图片上传报错
取消只看楼主 加入收藏
zdloveday
Rank: 2
等 级:论坛游民
帖 子:221
专家分:96
注 册:2008-9-5
结帖率:68.89%
收藏
 问题点数:0 回复次数:0 
图片上传报错
程序代码:
页面代码:
<form id="form1" method="post" enctype="multipart/form-data" runat="server">

 <p>
     <span>图片:</span>
     <input type="file" name="file" accept="image/*" />

 </p>
</form>

js

 _createForm: function (iframe) {
            var settings = this._settings;

            // We can't use the following code in IE6
            // var form = document.createElement('form');
            // form.setAttribute('method', 'post');
            // form.setAttribute('enctype', 'multipart/form-data');
            // Because in this case file won't be attached to request                    
            var form = toElement('<form method="post" enctype="multipart/form-data"></form>');

            form.setAttribute('action', settings.action);
            form.setAttribute('target', iframe.name);
            form.style.display = 'none';
            document.body.appendChild(form);

            // Create hidden input element for each data key
            for (var prop in settings.data) {
                if (settings.data.hasOwnProperty(prop)) {
                    var el = document.createElement("input");
                    el.setAttribute('type', 'hidden');
                    el.setAttribute('name', prop);
                    el.setAttribute('value', settings.data[prop]);
                    form.appendChild(el);
                }
            }
            return form;
        },
后端代码:

 try
            {
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase file = Request.Files[0];
                    string fileName = DateTime.Now.Ticks + "." + file.FileName.Substring(file.FileName.LastIndexOf(".") + 1);
                    string dateFolder = @"Uploads\" + DateTime.Now.Year + @"\" + DateTime.Now.Month + @"\" + DateTime.Now.Day + @"\";
                    string savePath = AppDomain.CurrentDomain.BaseDirectory + dateFolder;
                    if (!Directory.Exists(savePath))
                    {
                        Directory.CreateDirectory(savePath);
                    }
                    savePath += fileName;
                    file.SaveAs(savePath);
                    return "/" + dateFolder.Replace(@"\", "/") + fileName;
                }
            }
            catch (Exception exp)
            {
                LogHelper.WriteLog("UploadImg:" + exp.ToString(), LogType.Exception);
            }

错误提示:
Request.Files.Count = “Request.Files.Count”引发了类型“System.NullReferenceException”的异常    
搜索更多相关主题的帖子: form file var request DateTime 
2019-07-11 16:06
快速回复:图片上传报错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017691 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved