如何上传所有类型的图片?(.jpg,.gif,.png,bmp等.) [英] how to upload images of all types??(.jpg,.gif,.png,bmp etc..)

查看:101
本文介绍了如何上传所有类型的图片?(.jpg,.gif,.png,bmp等.)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否请您在(c#网络开发)中给我适当的代码,以上传所有类型的图像(.jpg,.gif,.png,bmp等.)
我收到了代码,但只上传了jpg ..
格式的图像 我想知道,上传除jpg以外的其他格式的图片有什么问题吗?
而且我还想要不允许上传任何重复图像的代码.


此外,我将把该图像名称存储在数据库中,并且当我上载图像时,我想将其显示在图像控件上
但是因为我仅上传单个图像,所以我不想使用任何完全数据绑定的控件,例如(Gridview,repeater或任何其他控件)..
怎么做??
谢谢:)

can you please give me a proper code in (c# web devolpment) to upload all types of images(.jpg,.gif,.png,bmp etc..)
i got the code but it only uploads images of the format jpg..
i want to know, is there any problem to upload images of the format other than jpg??
and also i want the code which would not allow to upload any duplicate image..


moreover i will store that image name on database and when i would upload the image, i would like to show it on an image control
but because i am uploading only single image so i do not want to use any fully data bound controls like (Gridview,repeater or any other)..
how to do it??
thanks :)

推荐答案

arvinder_aneja写道:
arvinder_aneja wrote:

我得到了代码,但只有上传jpg ..

i got the code but it only uploads images of the format jpg..


格式的图像
那是不可能的.网络应用程序通过不在乎要处理哪种文件的控件来上传您喜欢的任何文件.这是HTML中的唯一选项,因此也是ASP.NET中的唯一选项.

使用ASP.NET标记可让人们知道您是否正在编写Web应用程序.




That is impossible. A web app uploads any file you like, through a control that doesn''t care what sort of file it is dealing with. That''s the only option in HTML, and therefore in ASP.NET.

Use the ASP.NET tag to let people know if you''re writing a web app.


arvinder_aneja写道:
arvinder_aneja wrote:

而且我还希望该代码不允许上传任何重复的图像..

and also i want the code which would not allow to upload any duplicate image..



您可以检查是否使用了相同的文件名,但无法轻易分辨出两个图像是否完全相同,也就是说,对于较大的图像,没有一点代码也没有一点时间.



you can check if the same filename has been used, but you can''t easily tell if two images are exactly the same image, that is, not without a bit of code and a bit of time for larger images.

arvinder_aneja写道:
arvinder_aneja wrote:

此外,我会将图像名称存储在数据库中,并且当我上载图像时,我希望将其显示在图像控件上

moreover i will store that image name on database and when i would upload the image, i would like to show it on an image control



好,那很容易



OK, that''s easy

arvinder_aneja写道:
arvinder_aneja wrote:

但是因为我仅上传单个图像,所以我不想使用任何完全数据绑定的控件,例如(Gridview,repeater或任何其他).

but because i am uploading only single image so i do not want to use any fully data bound controls like (Gridview,repeater or any other)..



要在数据绑定控件中显示图像,请为显示img标签或asp:Image标签的列创建模板,并将图像路径绑定到控件.如果您只想显示单个图像,则只需一个img或asp:Image控件,然后将其绑定到您必须使用的单个路径上,实际上该任务没有什么区别,唯一的区别是添加了一个步骤,使其可以通过数据集处理许多图像.

顺便说一句,我非常感谢您声明您正在编写一个Web应用程序,并使用真实的英语提出您的问题.请只使用ASP.NET标记以及C#,这样,如果人们正在过滤要回答的问题,他们就会找到您的问题.我问这个问题仅是出于您的利益.



To show images in a data bound control, you''d create a template for a column that shows an img tag, or an asp:Image tag, and binds the image path to the control. If you only want to show a single image, you''d just have a single img or asp:Image control, and bind that to the single path that you have to work with, there''s literally no difference in the task, the only difference is adding a step to make it work with many images through a dataset.

Just to add, I appreciate you stating that you''re writing a web app, and using real English to ask your question. Please just use the ASP.NET tag as well as C#, so that if people are filtering for questions to answer, they will find yours. It''s really only for your benefit that I ask this.


请不要发布您自己问题的答案,除非您确实有要发布的答案.使用下面的论坛,或编辑您的帖子.

该代码非常简单.您说您有代码,但仅适用于jpg.您应该发布该代码(当要求人们帮助您时,您应该始终发布您的代码).重复的图片,您需要弄清楚图片路径(这是一个问题,为什么两个人不能上传两个不同的图像,都称为cat.jpg)还是两个相同的图像(它们构成了自己的图像)问题.如果要这样做,您应该阅读我的图像处理文章,您需要遍历整个图像并逐像素比较它,或者决定您愿意接受哪种样本作为它们的证据.相同的.如果我调整相同图像的大小并上传它该怎么办,您会接受吗?必须先定义问题,然后才能回答.

< asp:Image runat =服务器" ID ="image"/>

然后,当您上传文件时,将其保存并设置image.ImageUrl到保存该文件的路径,正如我所说的那样,这是您对最后一个问题的答案的总和,这太简单了,我认为,首先探索您所拥有的东西,然后问一问您从中学到了什么,以至于无法使用您的参考文献和/或Google来弄清诸如此类的基础知识,就更值得.
Please don''t post answers to your own question, unless you really have the answer to post. Use the forum below, or edit your post.

The code is very trivial. You say you have code but it only works for jpg. You should post that code ( you should ALWAYS post your code when asking people to help you with it ). The duplicate image thing, you need to clarify if you mean image path ( which is a problem, why can''t two people upload two different images both called cat.jpg ), or two identical images, which poses it''s own problems. You should read my image processing articles if you want to do that, you''d need to iterate over the whole image and compare it pixel by pixel, or decide on what sample you''re willing to accept as proof that they are the same. What if I resize the same image and upload it, will you accept that ? The question needs to be defined before it can be answered.

<asp:Image runat="server" ID="image"/>

and then when your file is uploaded, you save it and set image.ImageUrl to the path you saved it at, that''s the grand total of the answer to your last question, as I said, that''s so trivial, that I think it''s more worthwhile to explore what you have first, then ask where you''ve learned from, to not be able to work out basics like that using your references and/or google.


感谢您的支持..
但是我想要正确的代码来做..
或者我想要可以在其中找到链接的链接...
thanks for your support..
but i want the proper code to do this..
or i want the link where i can find this...


这篇关于如何上传所有类型的图片?(.jpg,.gif,.png,bmp等.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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