File uploader with javascript extension validation

I was recently creating a form that needed to upload an image only to an email handler.  The file would then get emailed to the client.

The way that we have always worked this, is the asp.net fileupload control posted back to the server and checked the fuImage.HasFile and then fuImage.FileName, maybe even using the FileInfo class to let it grab the extension, and check it against a list.

But I realised that is real old school, and with the loveliness of jQuery and regular expressions. Again the internet failed me almost, as there are not really good posts or helpers out there that do this. Everything that appears seems to be out of date, or does something similar but not what am wanting. Well here is a quick script to check the file extensions and inform the user if the file is an image or not:

$(document).ready(function () {

        $("#btnRegister").click(function () {
            // check if the file you are going to upload is an image or not.
            var filePath = $("#fileUpload").val();
            filePath = filePath.replace(/^\s|\s$/g, "");
            if (/\.\w+$/.test(filePath)) {
                var m = filePath.match(/([^\/\\]+)\.(\w+)$/);
                if (m) {
                    if (m[2] == "gif" || m[2] == "jpg" || m[2] == "png" || m[2] == "bmp") {
                        return true;
                    }
                }
            }

            alert("Please make sure you upload only pictures.");
            return false;

        });

    });

And that’s it. You can quite easily change the file extensions here to suit your needs, even try and do something fancy with call backs to the server with the file extension so you can read a dynamic list or from a config file or something, how should I know that’s you job fs!!

Glasgow Massages Work

I have to admit I love getting a regular massage, and Glasgow has an abundance of good places to go.  However there also can be a lot of bad ones to be careful.  Last week I was fortunate to be introduced to Julie, a newish kid on the massage block.  My yoga teacher introduced me to her as, Simone has been visiting Julie for a while.  Well I kid you not…Best.  Massage.  Ever.  I was so relaxed afterward I could hardly keep my eyes open!

So why not try it out for yourself if you live in the Glasgow area, or passing through…. Glasgow Massage Works (tell Julie I sent you!).

Using a Bespoke CDN with WordPress

I have been helping a friend with his website lately and again it started to slow down, due to the massive traffic the site gets.  The last time I checked the stats Elephant Journal get’s 250,000 visitors a month with approximately 450,000 page views!  That’s quite a busy wee site.

A while back we moved some of the static files off site, and that helped massive get the site another 70,000 visitors a month – people didn’t drop out or bounce while they were waiting for the site to load.  This was real easy to do, and just meant we pointed the URL of the file to the new server.  But now the site is slowing again, and I believe it is due to the massive number of images that get downloaded.  So how do you move all these images off site and update all the URLs?  WordPress comes to the rescue…but you need to do some coding. Read the rest of this entry »

Linq to Objects vs Generic List

If you know me, then you know I like to make things run fast.  I like testing performance of my software.  So with a recent website, I noticed that I query a tiny database table a lot.  There surely is a faster why to do it, and with Linq statements you can query in memory objects like Sql.  Nice…? Read the rest of this entry »

ASP.net Weird Bug

The Problem

Could someone explain the following to me.  I have a page with a couple of buttons on it.  They sit nicely next to each other with a  nice gap.  Here’s the Html (webforms): Read the rest of this entry »

ASP.net C# – List vs IList

Sorry for reopening this old debate, but I have been struggling with getting my head around this concept but came to a conclusion of my own. Read the rest of this entry »

Rate My Yoga Teacher

Lost in a yoga jungle

This weekend saw the launch of an idea I have been having for a week or so while now.  I have a great yoga teacher, but when she is unable to run a block of classes am kinda lost.  Where should I go?  Who should I speak to? ARGH!!  Ok it’s not that stressful, but it can be annoying, and I guess there are tonnes of people out there in similar boats from time to time.

So when a friend and colleague, said the same thing, I thought it was about time to do something.  When we were talking about the problem, we thought that maybe running a directory but one that was a rating site as well, would be a good idea.  That way, you can see a list of teachers in your area, and how others rate them.

So http://ratemyyogateacher.co.uk was born.  Now I have found a couple of other sites that do something similar, but they just don’t look appealing, or very easily useable.  So what will I bring to it.  Well am not sure yet.  It’s just new.  So go along to the site and register for the updates to the site.  I will let you know when it goes live…

Google Maps API v3 – Multiple Markers, Multiple Infowindows

Like many of you out there that use Google Maps, when v3.0 of it came out you jumped at the chance to use it!  But I couldn’t get the multiple markers, multiple info windows to work, no matter what I found on Google’s site.

Searching got me to this blog:

http://www.svennerberg.com/2009/09/google-maps-api-3-infowindows

And it states this guy is writing a book on this very subject.  So this should have the answer.  Well bollocks it did!  Stop writing your book now matey! Read the rest of this entry »

Fighting Cancer with Music

Many of you that read my blog The few of you that read my blog may have seen that I have been helping a good friend Donna, build her website and promote her charity Fighting Cancer with Music.  She is currently promoting an event in Taylor, Texas for her friend Jenny Tepernning:

The Jenny Benefit

So if you read this and you are in that area, please head along and find out more.

What’s also cool is this allowed me to post my first blog on the awesome blog site Elephant Journal.  Waylon Lewis was kind enough to let me post about what is Donna is up to.  He has a phenomenal following of regular 30K visitors, with 170K more than visit at least once a month.  So hopefully this will help Donna out in ways that I could never have possibly done.  Thanks Waylon!