Aşağıdaki c # komut bir yükleme sınıfının bir parçasıdır. Ben, bir php programcısı Ben c # çok ile berbat hiç ama öğrenmeye çalışıyorum. Bu yükleme komut görüntüler dışında, ben de diğer medya türleri işleyebilir, ya da hep birlikte yeniden yazmak için bu sınıfı uyarlamak için ihtiyacınız olan her şeyi idare edecek. Yanılmıyorsam, ben fark
using (Image image = Image.FromStream(file.InputStream))
temelde aşağıdaki kapsamı görüntü, sadece bir görüntü kullanılabilir veya nesne atılır söylüyor? Ve aynı zamanda değişken görüntü ben olmasını anlamak dosya akışı, gibi ... php $ _FILES diziden bir görüntü oluşturulmuş ediliyor?
Ben gerçekten şu anda ya bir yol küçültmek umurumda değil, bilmiyorum, yani bu dışarı alınır ve hala o tamamen sakinim yükleme işlemi olabilir, ben sadece bu şey almaya başlarken herhangi bir şans vardı değil dışında yorum görüntüleri bile bir şey ama, bu sınıfın bütün parçası ...
protected void Page_Load(object sender, EventArgs e)
{
string dir = Path.Combine(Request.PhysicalApplicationPath, "files");
if (Request.Files.Count == 0)
{
// No files were posted
Response.StatusCode = 500;
}
else
{
try
{
// Only one file at a time is posted
HttpPostedFile file = Request.Files[0];
// Size limit 100MB
if (file.ContentLength > 102400000)
{
// File too large
Response.StatusCode = 500;
}
else
{
string id = Request.QueryString["userId"];
string[] folders = userDir(id);
foreach (string folder in folders)
{
dir = Path.Combine(dir, folder);
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
}
string path = Path.Combine(dir, String.Concat(Request.QueryString["batchId"], "_", file.FileName));
file.SaveAs(path);
// Create thumbnail
int dot = path.LastIndexOf('.');
string thumbpath = String.Concat(path.Substring(0, dot), "_thumb", path.Substring(dot));
using (Image image = Image.FromStream(file.InputStream))
{
// Find the ratio that will create maximum height or width of 100px.
double ratio = Math.Max(image.Width / 100.0, image.Height / 100.0);
using (Image thumb = new Bitmap(image, new Size((int)Math.Round(image.Width / ratio), (int)Math.Round(image.Height / ratio))))
{
using (Graphics graphic = Graphics.FromImage(thumb))
{
// Make sure thumbnail is not crappy
graphic.SmoothingMode = SmoothingMode.HighQuality;
graphic.InterpolationMode = InterpolationMode.High;
graphic.CompositingQuality = CompositingQuality.HighQuality;
// JPEG
ImageCodecInfo codec = ImageCodecInfo.GetImageEncoders()[1];
// 90% quality
EncoderParameters encode = new EncoderParameters(1);
encode.Param[0] = new EncoderParameter(Encoder.Quality, 90L);
// Resize
graphic.DrawImage(image, new Rectangle(0, 0, thumb.Width, thumb.Height));
// Save
thumb.Save(thumbpath, codec, encode);
}
}
}
// Success
Response.StatusCode = 200;
}
}
catch
{
// Something went wrong
Response.StatusCode = 500;
}
}
}