Example #1
0
        public bool UploadContentPhotoImage(out string message, out string url, out string smallUrl, out string middleUrl, out string largeUrl)
        {
            message = url = smallUrl = middleUrl = largeUrl = string.Empty;

            if (Request.Files["ImageUrl"] == null)
            {
                return(false);
            }

            var postedFile = Request.Files["ImageUrl"];

            try
            {
                var fileName       = PathUtility.GetUploadFileName(PublishmentSystemInfo, postedFile.FileName);
                var fileExtName    = PathUtils.GetExtension(fileName).ToLower();
                var directoryPath  = PathUtility.GetUploadDirectoryPath(PublishmentSystemInfo, fileExtName);
                var fileNameSmall  = "small_" + fileName;
                var fileNameMiddle = "middle_" + fileName;
                var filePath       = PathUtils.Combine(directoryPath, fileName);
                var filePathSamll  = PathUtils.Combine(directoryPath, fileNameSmall);
                var filePathMiddle = PathUtils.Combine(directoryPath, fileNameMiddle);

                if (EFileSystemTypeUtils.IsImageOrFlashOrPlayer(fileExtName))
                {
                    if (!PathUtility.IsImageSizeAllowed(PublishmentSystemInfo, postedFile.ContentLength))
                    {
                        message = "上传失败,上传图片超出规定文件大小!";
                        return(false);
                    }

                    postedFile.SaveAs(filePath);

                    FileUtility.AddWaterMark(PublishmentSystemInfo, filePath);

                    var widthSmall  = PublishmentSystemInfo.Additional.PhotoSmallWidth;
                    var heightSamll = PublishmentSystemInfo.Additional.PhotoSmallHeight;
                    ImageUtils.MakeThumbnail(filePath, filePathSamll, widthSmall, heightSamll, true);

                    var widthMiddle  = PublishmentSystemInfo.Additional.PhotoMiddleWidth;
                    var heightMiddle = PublishmentSystemInfo.Additional.PhotoMiddleHeight;
                    ImageUtils.MakeThumbnail(filePath, filePathMiddle, widthMiddle, heightMiddle, true);

                    url = PageUtility.GetPublishmentSystemUrlByPhysicalPath(PublishmentSystemInfo, filePathSamll);

                    smallUrl  = PageUtility.GetVirtualUrl(PublishmentSystemInfo, url);
                    middleUrl = PageUtility.GetVirtualUrl(PublishmentSystemInfo, PageUtility.GetPublishmentSystemUrlByPhysicalPath(PublishmentSystemInfo, filePathMiddle));
                    largeUrl  = PageUtility.GetVirtualUrl(PublishmentSystemInfo, PageUtility.GetPublishmentSystemUrlByPhysicalPath(PublishmentSystemInfo, filePath));
                    return(true);
                }
                message = "您必须上传图片文件!";
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(false);
        }
Example #2
0
        public bool UploadContentPhotoSwfUpload(out string message, out string url, out string smallUrl, out string largeUrl)
        {
            message = url = smallUrl = largeUrl = string.Empty;

            if (Request.Files != null && Request.Files["Filedata"] != null)
            {
                var postedFile = Request.Files["Filedata"];

                try
                {
                    var fileName      = PathUtility.GetUploadFileName(PublishmentSystemInfo, postedFile.FileName);
                    var fileExtName   = PathUtils.GetExtension(fileName).ToLower();
                    var directoryPath = PathUtility.GetUploadDirectoryPath(PublishmentSystemInfo, fileExtName);
                    var fileNameSmall = "small_" + fileName;
                    var filePath      = PathUtils.Combine(directoryPath, fileName);
                    var filePathSmall = PathUtils.Combine(directoryPath, fileNameSmall);

                    if (EFileSystemTypeUtils.IsImageOrFlashOrPlayer(fileExtName))
                    {
                        if (!PathUtility.IsImageSizeAllowed(PublishmentSystemInfo, postedFile.ContentLength))
                        {
                            FailMessage("上传失败,上传图片超出规定文件大小!");
                            return(false);
                        }

                        postedFile.SaveAs(filePath);

                        FileUtility.AddWaterMark(PublishmentSystemInfo, filePath);

                        var widthSmall = 200;
                        ImageUtils.MakeThumbnail(filePath, filePathSmall, widthSmall, 0, true);

                        url = PageUtility.GetPublishmentSystemUrlByPhysicalPath(PublishmentSystemInfo, filePathSmall);

                        smallUrl = PageUtility.GetVirtualUrl(PublishmentSystemInfo, url);
                        largeUrl = PageUtility.GetVirtualUrl(PublishmentSystemInfo, PageUtility.GetPublishmentSystemUrlByPhysicalPath(PublishmentSystemInfo, filePath));
                        return(true);
                    }
                    else
                    {
                        message = "您必须上传图片文件!";
                    }
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                }
            }
            return(false);
        }
        //将编辑器中图片上传至本机
        public static string SaveImage(SiteInfo siteInfo, string content)
        {
            var originalImageSrcs = RegexUtils.GetOriginalImageSrcs(content);

            foreach (var originalImageSrc in originalImageSrcs)
            {
                if (!PageUtils.IsProtocolUrl(originalImageSrc) ||
                    StringUtils.StartsWithIgnoreCase(originalImageSrc, PageUtils.ApplicationPath) ||
                    StringUtils.StartsWithIgnoreCase(originalImageSrc, siteInfo.Additional.WebUrl))
                {
                    continue;
                }
                var fileExtName = PageUtils.GetExtensionFromUrl(originalImageSrc);
                if (!EFileSystemTypeUtils.IsImageOrFlashOrPlayer(fileExtName))
                {
                    continue;
                }

                var fileName      = GetUploadFileName(siteInfo, originalImageSrc);
                var directoryPath = GetUploadDirectoryPath(siteInfo, fileExtName);
                var filePath      = PathUtils.Combine(directoryPath, fileName);

                try
                {
                    if (!FileUtils.IsFileExists(filePath))
                    {
                        WebClientUtils.SaveRemoteFileToLocal(originalImageSrc, filePath);
                        if (EFileSystemTypeUtils.IsImage(PathUtils.GetExtension(fileName)))
                        {
                            FileUtility.AddWaterMark(siteInfo, filePath);
                        }
                    }
                    var fileUrl = PageUtility.GetSiteUrlByPhysicalPath(siteInfo, filePath, true);
                    content = content.Replace(originalImageSrc, fileUrl);
                }
                catch
                {
                    // ignored
                }
            }
            return(content);
        }
Example #4
0
        //将编辑器中图片上传至本机
        public static string SaveLibraryImage(string content)
        {
            var originalImageSrcs = RegexUtils.GetOriginalImageSrcs(content);

            foreach (var originalImageSrc in originalImageSrcs)
            {
                if (!PageUtils.IsProtocolUrl(originalImageSrc) ||
                    StringUtils.StartsWithIgnoreCase(originalImageSrc, PageUtils.ApplicationPath))
                {
                    continue;
                }
                var fileExtName = PageUtils.GetExtensionFromUrl(originalImageSrc);
                if (!EFileSystemTypeUtils.IsImageOrFlashOrPlayer(fileExtName))
                {
                    continue;
                }

                var fileName    = GetLibraryFileName(originalImageSrc);
                var virtualPath = GetLibraryVirtualPath(EUploadType.Image, fileName);
                var filePath    = Combine(WebConfigUtils.PhysicalApplicationPath, virtualPath);

                try
                {
                    if (!FileUtils.IsFileExists(filePath))
                    {
                        WebClientUtils.SaveRemoteFileToLocal(originalImageSrc, filePath);
                    }
                    content = content.Replace(originalImageSrc, virtualPath);
                }
                catch
                {
                    // ignored
                }
            }
            return(content);
        }
Example #5
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (HifUpload.PostedFile == null || "" == HifUpload.PostedFile.FileName)
            {
                return;
            }

            var filePath = HifUpload.PostedFile.FileName;

            try
            {
                var fileExtName        = PathUtils.GetExtension(filePath).ToLower();
                var localDirectoryPath = PathUtility.GetUploadDirectoryPath(SiteInfo, fileExtName);
                if (!string.IsNullOrEmpty(_realtedPath))
                {
                    localDirectoryPath = PathUtility.MapPath(SiteInfo, _realtedPath);
                    DirectoryUtils.CreateDirectoryIfNotExists(localDirectoryPath);
                }
                var localFileName = PathUtility.GetUploadFileName(SiteInfo, filePath, TranslateUtils.ToBool(DdlIsFileUploadChangeFileName.SelectedValue));

                var localFilePath = PathUtils.Combine(localDirectoryPath, localFileName);

                if (_uploadType == EUploadType.Image && !EFileSystemTypeUtils.IsImageOrFlashOrPlayer(fileExtName))
                {
                    FailMessage("此格式不允许上传,此文件夹只允许上传图片以及音视频文件!");
                    return;
                }
                if (_uploadType == EUploadType.Video && !EFileSystemTypeUtils.IsImageOrFlashOrPlayer(fileExtName))
                {
                    FailMessage("此格式不允许上传,此文件夹只允许上传图片以及音视频文件!");
                    return;
                }
                if (_uploadType == EUploadType.File && !PathUtility.IsFileExtenstionAllowed(SiteInfo, fileExtName))
                {
                    FailMessage("此格式不允许上传,请选择有效的文件!");
                    return;
                }

                if (!PathUtility.IsFileSizeAllowed(SiteInfo, HifUpload.PostedFile.ContentLength))
                {
                    FailMessage("上传失败,上传文件超出规定文件大小!");
                    return;
                }

                HifUpload.PostedFile.SaveAs(localFilePath);

                FileUtility.AddWaterMark(SiteInfo, localFilePath);

                var fileUrl    = PageUtility.GetSiteUrlByPhysicalPath(SiteInfo, localFilePath, true);
                var textBoxUrl = PageUtility.GetVirtualUrl(SiteInfo, fileUrl);

                if (string.IsNullOrEmpty(_textBoxClientId))
                {
                    LayerUtils.Close(Page);
                }
                else
                {
                    LtlScript.Text = $@"
<script type=""text/javascript"" language=""javascript"">
    if (parent.document.getElementById('{_textBoxClientId}') != null)
    {{
        parent.document.getElementById('{_textBoxClientId}').value = '{textBoxUrl}';
    }}
    {LayerUtils.CloseScript}
</script>";
                }
            }
            catch (Exception ex)
            {
                FailMessage(ex, "文件上传失败");
            }
        }
Example #6
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (hifUpload.PostedFile != null && "" != hifUpload.PostedFile.FileName)
            {
                var filePath = hifUpload.PostedFile.FileName;

                try
                {
                    var fileExtName        = PathUtils.GetExtension(filePath).ToLower();
                    var localDirectoryPath = PathUtility.GetUploadDirectoryPath(PublishmentSystemInfo, fileExtName);
                    if (!string.IsNullOrEmpty(_realtedPath))
                    {
                        localDirectoryPath = PathUtility.MapPath(PublishmentSystemInfo, _realtedPath);
                        DirectoryUtils.CreateDirectoryIfNotExists(localDirectoryPath);
                    }
                    var localFileName = PathUtility.GetUploadFileName(PublishmentSystemInfo, filePath, DateTime.Now, TranslateUtils.ToBool(rblIsFileUploadChangeFileName.SelectedValue));

                    var localFilePath = PathUtils.Combine(localDirectoryPath, localFileName);

                    if (_uploadType == EUploadType.Image && !EFileSystemTypeUtils.IsImageOrFlashOrPlayer(fileExtName))
                    {
                        FailMessage("此格式不允许上传,此文件夹只允许上传图片以及音视频文件!");
                        return;
                    }
                    if (_uploadType == EUploadType.Video && !EFileSystemTypeUtils.IsImageOrFlashOrPlayer(fileExtName))
                    {
                        FailMessage("此格式不允许上传,此文件夹只允许上传图片以及音视频文件!");
                        return;
                    }
                    if (_uploadType == EUploadType.File && !PathUtility.IsFileExtenstionAllowed(PublishmentSystemInfo, fileExtName))
                    {
                        FailMessage("此格式不允许上传,请选择有效的文件!");
                        return;
                    }

                    if (!PathUtility.IsFileSizeAllowed(PublishmentSystemInfo, hifUpload.PostedFile.ContentLength))
                    {
                        FailMessage("上传失败,上传文件超出规定文件大小!");
                        return;
                    }

                    hifUpload.PostedFile.SaveAs(localFilePath);

                    FileUtility.AddWaterMark(PublishmentSystemInfo, localFilePath);

                    var fileUrl    = PageUtility.GetPublishmentSystemUrlByPhysicalPath(PublishmentSystemInfo, localFilePath);
                    var textBoxUrl = PageUtility.GetVirtualUrl(PublishmentSystemInfo, fileUrl);

                    if (string.IsNullOrEmpty(_textBoxClientId))
                    {
                        PageUtils.CloseModalPage(Page);
                    }
                    else
                    {
                        ltlScript.Text += $@"
if (parent.document.getElementById('{_textBoxClientId}') != null)
{{
    parent.document.getElementById('{_textBoxClientId}').value = '{textBoxUrl}';
}}
";

                        ltlScript.Text += PageUtils.HidePopWin;
                    }
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "文件上传失败");
                }
            }
        }