如何在不使用c#asp.net中的FileUpload Control的情况下将图像保存到路径或文件夹中? [英] How to image save in to the path or folder, without using FileUpload Control in c# asp.net?

查看:70
本文介绍了如何在不使用c#asp.net中的FileUpload Control的情况下将图像保存到路径或文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



如何在c#asp.net中不使用FileUpload Control进行图像保存?

我有一个简单的图像框和我想要将此图像框保存到路径或文件夹中。



我正在尝试使用此jquery代码上传图像。

 Fileupload.prototype.change = function(e){
if(e.target.files === undefined)e.target.files = e.target&& e.target.value? [{name:e.target.value.replace(/^.+ \\ /,'')}]:[]
if(e.target.files.length === 0)return

this。$ hidden.val('')
this。$ hidden.attr('name','')
this。$ input.attr('name', this.name)

var file = e.target.files [0]

if(this。$ preview.length> 0&&(typeof file。 type!==undefined?file.type.match('image。*'):file.name.match(/ \。(gif | png | jpe?g)$ / i))&& typeof FileReader!==undefined){
var reader = new FileReader()
var preview = this。$ preview
var element = this。$ element

reader.onload = function(re){
var $ img = $('< img>')。attr('src',re.target.result)
e.target.files [0 ] .result = re.target.result

element.find('。fileinput-filename')。text(file.name)

//如果父母有最大值 - 身高,使用`(max-)身高:100%`on child不考虑填充和边框考虑
if(preview.css('max-height')!='none')$ img.css('max -height',parseInt(preview.css('max-height'),10) - parseInt(preview.css('padding-top'),10) - parseInt(preview.css('padding-bottom'),10 ) - parseInt(preview.css('border-top'),10) - parseInt(preview.css('border-bottom'),10))

preview.html($ img)
element.addClass('fileinput-exists')。removeClass('fileinput-new')

element.trigger('change.bs.fileinput',e.target.files)
$('#HFLogoPath')。val(file.name);

}

reader.readAsDataURL(file)

} else {
this。$ element.find('。fileinput-filename ')。text(file.name)
this。$ preview.text(file.name)

this。$ element.addClass('fileinput-exists')。removeClass('fileinput -new')

this。$ element.trigger('change.bs.fileinput')
}
},



但我的图片没有保存到我的server.mappath。



请帮帮我。



先谢谢。



Ankit Agarwal

网站应用程序开发人员

解决方案

< blockquote> hidden.val('')
this。


hidden.attr('name','')
this。


input.attr('name',this.name)

var file = e.target.files [0]

if(this。

Hello,

How to image save without using FileUpload Control in c# asp.net?
I have a simple imagebox and I want to image save of this image box, in to the path or folder.

I am trying this jquery code for upload image.

Fileupload.prototype.change = function (e) {
      if (e.target.files === undefined) e.target.files = e.target && e.target.value ? [{ name: e.target.value.replace(/^.+\\/, '')}] : []
      if (e.target.files.length === 0) return

      this.$hidden.val('')
      this.$hidden.attr('name', '')
      this.$input.attr('name', this.name)

      var file = e.target.files[0]

      if (this.$preview.length > 0 && (typeof file.type !== "undefined" ? file.type.match('image.*') : file.name.match(/\.(gif|png|jpe?g)$/i)) && typeof FileReader !== "undefined") {
          var reader = new FileReader()
          var preview = this.$preview
          var element = this.$element

          reader.onload = function (re) {
              var $img = $('<img>').attr('src', re.target.result)
              e.target.files[0].result = re.target.result

              element.find('.fileinput-filename').text(file.name)

              // if parent has max-height, using `(max-)height: 100%` on child doesn't take padding and border into account
              if (preview.css('max-height') != 'none') $img.css('max-height', parseInt(preview.css('max-height'), 10) - parseInt(preview.css('padding-top'), 10) - parseInt(preview.css('padding-bottom'), 10) - parseInt(preview.css('border-top'), 10) - parseInt(preview.css('border-bottom'), 10))

              preview.html($img)
              element.addClass('fileinput-exists').removeClass('fileinput-new')

              element.trigger('change.bs.fileinput', e.target.files)
              $('#HFLogoPath').val(file.name);

          }

          reader.readAsDataURL(file)
          
      } else {
          this.$element.find('.fileinput-filename').text(file.name)
          this.$preview.text(file.name)

          this.$element.addClass('fileinput-exists').removeClass('fileinput-new')

          this.$element.trigger('change.bs.fileinput')
      }
  },


but my image did not save into the my server.mappath.

Please help me.

Thanks in Advance.

Ankit Agarwal
Website Application Developer

解决方案

hidden.val('') this.


hidden.attr('name', '') this.


input.attr('name', this.name) var file = e.target.files[0] if (this.


这篇关于如何在不使用c#asp.net中的FileUpload Control的情况下将图像保存到路径或文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆