• dev uploadcontrol 上传图片


    <script type="text/javascript">
    // <![CDATA[
    function Uploader_OnUploadStart() {
    btnUpload.SetEnabled(false);
    }
    function Uploader_OnFileUploadComplete(args) {
    var imgSrc = aspxPreviewImgSrc;
    if (args.isValid) {
    var date = new Date();
    imgSrc = "/UploadImages/" + args.callbackData + "?dx=" + date.getTime();
    }
    getPreviewImageElement().src = imgSrc;
    }
    function Uploader_OnFilesUploadComplete(args) {
    UpdateUploadButton();
    }
    function UpdateUploadButton() {
    btnUpload.SetEnabled(uploader.GetText(0) != "");
    }
    function getPreviewImageElement() {
    return document.getElementById("previewImage");
    }
    // ]]>
    </script>

    <script type="text/javascript">
    // <![CDATA[
    var aspxPreviewImgSrc = getPreviewImageElement().src;
    // ]]>
    </script>

    <!--添加图片-->
    <table style=" 500px;padding-left:20px;">
    <tr>
    <td style="300px">
    <dx:ASPxUploadControl ID="uplImage" runat="server" ClientInstanceName="uploader" ShowProgressPanel="True"
    NullText="Click here to browse files..." Size="35" OnFileUploadComplete="uplImage_FileUploadComplete">
    <ClientSideEvents FileUploadComplete="function(s, e) { Uploader_OnFileUploadComplete(e); }"
    FilesUploadComplete="function(s, e) { Uploader_OnFilesUploadComplete(e); }"
    FileUploadStart="function(s, e) { Uploader_OnUploadStart(); }"
    TextChanged="function(s, e) { UpdateUploadButton(); }"></ClientSideEvents>
    <ValidationSettings MaxFileSize="4194304" AllowedFileExtensions=".jpg,.jpeg,.jpe,.gif,.png">
    </ValidationSettings>
    </dx:ASPxUploadControl>
    </td>
    <td style="100px">
    <dx:ASPxButton ID="btnUpload" runat="server" AutoPostBack="False" Text="Upload" ClientInstanceName="btnUpload"
    Width="100px" ClientEnabled="False" Style="margin: 0 auto;">
    <ClientSideEvents Click="function(s, e) { uploader.Upload(); }" />
    </dx:ASPxButton>
    </td>
    </tr>
    </table>
    <table style=" 500px">
    <tr>
    <td style="padding-right: 20px; vertical-align: top;"></td>
    <td class="imagePreviewCell">
    <img src="../Content/ImagePreview.gif" id="previewImage" alt="" style=" 490px; height: 200px;" /></td>
    </tr>
    </table>

    后台代码:

    string UploadDirectory = "/UploadImages/";
    string ThumbnailFileName = Guid.NewGuid().ToString();
    protected void uplImage_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e)
    {
    ThumbnailFileName += e.UploadedFile.FileName;
    e.CallbackData = SavePostedFile(e.UploadedFile);
    }
    string SavePostedFile(UploadedFile uploadedFile)
    {
    if (!uploadedFile.IsValid)
    return string.Empty;
    string fileName = Path.Combine(MapPath(UploadDirectory), ThumbnailFileName);
    uploadedFile.SaveAs(fileName);
    Session["pathpicture"] = UploadDirectory+ThumbnailFileName;
    return ThumbnailFileName;
    }

  • 相关阅读:
    ThinkPhp框架分页查询和部分框架知识
    tp框架增删改
    WAMP中mysql服务突然无法启动 解决方法
    thinkphp框架 的 链接数据库和操作数据
    php 全局使用laravel的dd和dump
    给centos装图形界面 widowsx
    marquee标签的使用
    微信公众号开发入门教程
    laravel admin引入css js报错 https
    利用Croppie裁剪图片并后台保存
  • 原文地址:https://www.cnblogs.com/zhang-wenbin/p/5891421.html
Copyright © 2020-2023  润新知