コード例 #1
0
        private void CheckUploadedFiles(IEnumerable <HttpPostedFileBase> files, int order, ref string warning)
        {
            if (files != null)
            {
                foreach (var file in files)
                {
                    if (file.ContentType == "image/jpg" || file.ContentType == "image/jpeg" || file.ContentType == "image/pjpeg")
                    {
                        var im = ImageHelper.GetImageFromStream(file.InputStream);
                        if (!ImageHelper.IsImageSrgbJpeg(im))
                        {
                            warning += "The image has wrong profile please convert it to “SRGB” profile";
                        }
                    }
                    // Some browsers send file names with full path. We only care about the file name.
                    var fileName = FileHelper.PrepareFileName(Path.GetFileNameWithoutExtension(file.FileName)) + Path.GetExtension(file.FileName);
                    var dir      = Models.UrlHelper.GetUploadImagePath();
                    fileName = FileHelper.GetNotExistFileName(dir, fileName);
                    var destinationPath = Path.Combine(dir, fileName);

                    file.SaveAs(destinationPath);
                    SessionHelper.AddUploadedImage(fileName, order);
                }
            }
        }