AJAX file uploads using jQuery

About time we can do this! Check it out! In the example below my file input is called #evidence. The dataType option sets what jQuery can expect to receive back in the response, in this case, I send back JSON.

                var jform = new FormData();
                    url: '/your-form-processing-page-url-here',
                    type: 'POST',
                    data: jform,
                    dataType: 'json',
                    mimeType: 'multipart/form-data',
                    contentType: false,
                    cache: false,
                    processData: false,
                    success: function(data, status, jqXHR){
                        alert('Hooray! All is well.');
                    error: function(jqXHR,status,error){
                        // Hopefully we should never reach here

Lost connection to MySQL server at ‘reading initial communication packet’

Here’s one you might have had. “Lost connection to MySQL server at ‘reading initial communication packet’ “.

If  you get this, then I assume that you are connecting to another machine on the network, a virtual machine, or a remote server.

It’s a pretty simple fix. Edit your /etc/mysql/my.cnf (path may differ depending on your setup), and change the line that says bind-address = to:

bind-address =

Save it, then restart mysql.

sudo service mysql restart

Job done!

chmod, chown, & chgrp – Permissions on a PuPHPet Vagrant Box

PuPHPet and Vagrant are awesome. If you develop on Windoze, you are either off your head, or have no choice in the workplace. Right now I fall into the latter category. I noticed XAMPP installed. Yeah right. No chance. Anyway, using PuPHPet and Vagrant is a far better way of doing things regardless of your OS, as it means you can move your entire development environment anywhere without having to reconfigure anything! See my post https://delboy1978uk.wordpress.com/2014/08/18/using-puphpet-and-vagrant/ for info on getting set up and running.

Anyway, it turns out that the files and directories for your sites are all owned by www-data, and are in the www-data group. I was trying to run a PHP CLI command, however, as the logged in user is vagrant and the permissions were only executable for the owner, I tried running chmod, and chgroup, and chown, with no success. Because these are mounted folders and not actually in the VM, altering the permissions the normal way is impossible.

The solution is to go into your VagrantFile, and add the following:

config.vm.synced_folder "./mysite/scripts", "/var/www/mysite/scripts",
        owner: "www-data",
        group: "www-data",
        mount_options: ["dmode=775,fmode=775"]

The first path given is relative to your host OS directory with your site folders inside, the second path is the path on the VM. dmode I’m guessing is the directory permissions, fmode is the file permissions. I keyed this in just before the ‘end’  line at the bottom of the VagrantFile.

To make the changes, you can type vagrant up (if you havent started yet), or vagrant reload. Permissions have now been changed!

One last thing. Once I was able to execute, I ran my script and got

: No such file or directory

This again is a stupid character encoding issue due to windows, and the way I sorted it was to cat the file in Putty, and select the text, nano a new file, paste it in, delete the original, and rename the new file. I didnt have to chmod anything, all files in here now default to 775.

Anyway, now that problem has been solved I can get back on with my work! Cheers! 😀


It appears that the Vagrant file has been broken up into smaller more specific parts. In a recent puPHPet Vagrant box, I had to paste it in the puphpet/vagrant/vagrantfile-local file,  right before the very last line (which just says end).