It looks like you're new here. If you want to get involved, click one of these buttons!
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FileUpload.ascx.cs" Inherits="FileUpload" %>
<link rel="stylesheet" href="/css/general.css" type="text/css" media="screen" />
<link href="/Scripts/uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="/Scripts/uploadify/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/Scripts/uploadify/swfobject.js"></script>
<script type="text/javascript" src="/Scripts/uploadify/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
// <![CDATA[
var id = "55";
var theString = "asdf";
$(document).ready(function () {
$('#fileInput').uploadify({
'uploader': '/Scripts/uploadify/uploadify.swf',
'script': 'UploadImagesHandler.ashx',
'cancelImg': '/Scripts/uploadify/cancel.png',
'auto': true,
'multi': true,
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg',
'queueSizeLimit': 90,
'sizeLimit': 4000000,
'buttonText': 'Vaelg billeder',
'folder': '/uploads',
'displayData': 'speed',
'onAllComplete': function (event, data) { $('#status-message').text(data.filesUploaded + ' files uploaded, ' + data.errors + ' errors.'); }
});
});
// ]]></script>
<form runat="server">
<input id="fileInput" name="fileInput" type="file" />
</form>
public class UploadImagesHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
System.Collections.Generic.List<umbraco.cms.businesslogic.media.Media> images = new System.Collections.Generic.List<umbraco.cms.businesslogic.media.Media>();
HttpPostedFile file = context.Request.Files["FileData"];
umbraco.cms.businesslogic.media.Media m = umbraco.cms.businesslogic.media.Media.MakeNew(
file.FileName, umbraco.cms.businesslogic.media.MediaType.GetByAlias("image"), umbraco.BusinessLogic.User.GetUser(0), 1212);
string mediaRootPath = "d:/web/localuser/nuanceweb.dk/cms/media/";
string storagePath = mediaRootPath + m.Id.ToString();
System.IO.Directory.CreateDirectory(storagePath);
string fullFilePath = storagePath + "\\" + file.FileName;
file.SaveAs(fullFilePath);
System.IO.FileStream fs = new System.IO.FileStream(fullFilePath,
System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
System.Drawing.Image image = System.Drawing.Image.FromStream(fs);
fs.Close();
System.Drawing.Bitmap bmp = System.Drawing.Bitmap.FromFile(fullFilePath) as System.Drawing.Bitmap;
bmp = ResizeImage(bmp, 550, bmp.Height);
bmp.Save(fullFilePath, System.Drawing.Imaging.ImageFormat.Jpeg);
int fileWidth;
int fileHeight;
fileWidth = bmp.Width;
fileHeight = bmp.Height;
bmp.Dispose();
string ext = file.ContentType.Replace("image/", string.Empty);
string fileNameThumb = fullFilePath.Replace("." + ext, "_thumb");
generateThumbnail(image, 100, fileWidth, fileHeight, fullFilePath, ext, fileNameThumb + ".jpg");
m.getProperty("umbracoExtension").Value = ext;
m.getProperty("umbracoBytes").Value = file.ContentLength;
m.getProperty("umbracoHeight").Value = fileHeight;
m.getProperty("umbracoWidth").Value = fileWidth;
string mediaPath = "/media/" + m.Id.ToString() + "/" + file.FileName;
m.getProperty("umbracoFile").Value = mediaPath;
m.XmlGenerate(new System.Xml.XmlDocument());
}
public bool IsReusable {
get {
return false;
}
}
context.Response.Write("Success");