是否可以使用文件上传控件一次只上传文件的图像和视频类型? [英] Is it possible to use a file upload control to upload only image and video type of file at one time?

查看:339
本文介绍了是否可以使用文件上传控件一次只上传文件的图像和视频类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本准则仅适用于多个图像/多个视频。但是,如果我想在单个文件上传控件中上传包含多个视频的多个图像,那么只能从该控件上传图像和视频,而不是其他内容。

请注意我在SQl服务器数据库中保存图像路径并在asp.net文件夹中保存图像。



提前使用。\\ br />


我的尝试:



The Code is working perfectly only for multiple images/multiple videos. But what if I want to Upload multiple images with multiple videos in single file upload control so that only images and video can be uploaded from that control and nothing else.
Please Note that I am saving image path in SQl server database and image in asp.net folder.

Thanx in advance.

What I have tried:

 <div class="form-group">
                                    <div class="col-sm-2">
                                        <asp:Label ID="lblUpload" runat="server" Text="Upload Photo/Video" CssClass="form-control"></asp:Label>
                                    </div>
                                    <div class="col-sm-6">
                                        <asp:FileUpload ID="FileUploadBlog" runat="server" CssClass="fileinput fileinput-new" AllowMultiple="true" />
                                    </div>
<pre><div class="col-sm-12">
                                        <asp:Button ID="btnBlogPost" runat="server" Text="Post" CssClass="btn btn-facebook" OnClick="btnBlogPost_Click" />
                                    </div>
                                    <div class="col-sm-4">
                                        <asp:Label ID="lblErrorUplaod" runat="server" Visible="false" CssClass="label-danger">
                                    </div>







代码背后:




Code behind:

 string ext = System.IO.Path.GetExtension(this.FileUpload.PostedFile.FileName);
foreach (var file in FileUpload.PostedFiles)
{
   if (ext == ".jpeg" || ext == ".png" || ext == ".bmp" || ext == ".jpg")
   {
      if (FileUpload.PostedFile.ContentLength > 0 && FileUpload.PostedFile.ContentLength <= 625000)
      {.............................}
      else if (ext == ".mpeg4" || ext == ".mp4" || ext == ".3gp" || ext == ".flv")
      {
          if (FileUpload.PostedFile.ContentLength > 0 && FileUpload.PostedFile.ContentLength <= 625000)
         {.............................}
      }

推荐答案

好吧,您可以使用文件上传控件的accept属性,您可以在其中指定所需的所有有效文件扩展名。在此之后,浏览器窗口将仅显示与可上传的扩展名匹配的文件。

但这不是万无一失的,因为用户可以在下拉列表中自由选择所有文件类型并选择任何文件他想要。



如果你想限制用户选择无效的文件类型,你可能想要编写自己的组件。
Well, you can use the "accept" attribute of the file upload control where you can specify all the valid file extensions you want. After this, the browser window will only show files matching the extensions available to upload.
But this is not foolproof, as the user is free to select all file types in the drop-down and select any file he wants.

If you wish to restrict the user from selecting invalid file types, you may want to write your own component.


这篇关于是否可以使用文件上传控件一次只上传文件的图像和视频类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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