IAMIAN.ME

Follow me on twitter

Plupload: Setting Custom Filenames on Uploads

On a recent project I was attempting to get pluploader to set custom file names for uploaded images. After much googling I still had no solution, so I started fiddling with the file properties. Here is my solution:

<script type="text/javascript">
$(function() {
    $("#uploader").pluploadQueue({
        runtimes : 'html5,flash',
        url : '/plupload/upload.php',
        chunk_size : '1mb',
        rename : true,
        resize : {width : 1024, height : 768, quality : 90},
        filters : [
            {title : "Image files", extensions : "jpg,gif,png"},
            {title : "Zip files", extensions : "zip"}
        ],
        flash_swf_url : '/plupload/js/plupload.flash.swf',
    });

    var uploader = $('#uploader').pluploadQueue();

    $('form').submit(function(e) {
        if (uploader.files.length > 0) {
            uploader.bind('StateChanged', function() {
                if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                    $('form')[0].submit();
                }
            });

            uploader.start();
        } else {
            alert('You must queue at least one file.');
        }
        return false;
    });
    uploader.bind('FileUploaded',function(up,file){
        console.log(file);
    });

    //generate a random id
    var id = Math.floor(Math.random()*100000);

    uploader.bind('FilesAdded',function(up,files){
        var i = 1;
        $(files).each(function(){
            var fileExt = this.name.match(/\....$/);
            this.name = adid+'_'+i+fileExt;
            i++;
            console.log(this);
        });
    });
});
</script>

The Important bit is the FilesAdded event at the end. what its doing is changing the file.name property to a predetermined id suffixed by a counter. this results in the file being upladed with the value in file.name rather than the file name from the local file system

Zend: Preventing the layouts and/or scripts

Working on a controller that provides json response recently, I kept getting the annoying “controller/action.phtml not found” error. I didnt WANT a view for this particular method. some quick googling turned up:


#disable layouts:
$this->_helper->layout()->disableLayout();

#disable view
$this->_helper->viewRenderer->setNoRender();

Web Storage: Giant Cookie-Free Cookies… Only Better

Ah, Cookies. Alternatively maligned and lauded, cookies have been a fixture of web life for years. This is (or may be) changing as the new era of HTML5 (well, not really, but still) specs come into fruition. The Web Storage spec  gives us an alternative: Web Storage. With larger capacities and event triggers, along with several other advantages, it is my hope that this will come to common usage sooner rather than later.

Read the rest of this entry »

More training… Quite yay though.

Yesterday was more informative than I anticipated. We covered the basics, being mostly semantic tags and such. Today has been form validation and canvas.

Hopefully we move on to web storage and geo location shortly.

I am slowly going through training, 1 2 3 4 5 6 switch!

Going through training slowly am I 6 5 4 3 2 1 switch!

This week I am stuck in html5 training. It promises to be rather interesting. I will likely be writing some quick and dirty tutorial type posts for the hell of it.

Or not. I am famously lax in my blogging. We’ll see.