Only listen to yourself

This is probably the most genuine post I’ll write. Generally, I am genuine, but I very rarely say things without fitting (or trying to fit) in some sort of lighthearted sarcasm or humour. But this post is something I’ve learnt over the last 12 months and I feel like I should share it.

Probably four weeks ago, I decided to swim the equivalent of the (English) channel to help fundraise for Ecuador. When I told my parents, they hit the roof. It has only been ten months since I got taken to hospital with suspected heart palpitations and I don’t think swimming 22 miles in the space of a week was something they thought would be a good idea. I calmed them by saying I had a  full week -thats 3 miles a day. Secretly, I was thinking I could do it in 5 days – 4.5 miles a day.

Meanwhile, a similar situation comes to mind when I moved in. One of my neighbours greeted me when I went around dropping in notes to inform them of a forthcoming housewarming. “How is the house coming along?” Was the main theme of the conversation, to which I ended up telling them about how I was going to sort out the garden. The general response was “good luck, you’ll never get it done!”

I could continue to recall situations where this happens. Back in October when I planned the walk across Wales with Ed, a year or so back when I cycled South Wales to North Wales on my dad’s old mountain bike. I’m used to people telling me things can’t be done, or that I can’t do them.

Most importantly, I’ve consistently proved them wrong. This morning, I finished my 22 mile 1413 length swim, in 2 and 1/2 days. Thats half the time I thought I could do it myself! The walk across Wales, bike ride and numerous other things I’ve done were successful. So when someone tells you that you can’t do something, don’t think “oh ok then” because that way, you are not believing in yourself. Either prove them wrong, or give it a damn good go trying.

I’m not bragging about my achievements. There are people who have achieved loads more than me, and in shorter times. On the face of things, I don’t feel like I have achieved that much, but the main thing is that I complete what I set out to do. As long as I do that, I’ll be happy, and proud. I’m sure I’ll make my parents proud too. I should also add that once my parents get over the shock of my ‘latest idea’ they are, and have been awesomely supportive.

On that note, I’m off to do a few hours work in the garden. I’ve still got one more person to prove wrong!

 

Uploadify – How to Rename an Uploaded File

I’ve recently got to grips with Uploadify – a great little jQuery plugin that allows you to simply upload images in a crazily easy to use form. However the images will overwrite, and I wanted to prevent this by renaming it if there was a clash.

This wasn’t too difficult. In uploadify.php, you will find the code that actually deals with the moving of the uploaded file.

Simply adding a file_exists function to the code allowed me to check if I needed to rename the file. Adding a number to the end of it and counting up until it no longer had a clash does the trick. You can also plug in some more stuff here, like creating thumbnails.

  if(file_exists($targetFile)){

    //we need to rename the file here to avoid a clash.
    //Add a number to the end until it doesn't clash
    $info = pathinfo($targetFile);
    $file_name = basename($targetFile,'.'.$info['extension']);
    $count=1;
    while(file_exists($file_name."_".$count.$info['extension'])){
      ++$count;
    }
    $targetFile = $info['dirname'].'/'.$file_name.'_'.$count.'.'.$info['extension'];
  }
  move_uploaded_file($tempFile,$targetFile);

Anyway, this still causes a problem. if you are using the onComplete function call, you will find that the fileObj.name returns the original file name, not the new one. The solution? Read the response instead, which will contain the original file name.

  'onComplete' : function(event, ID, fileObj, response, data){
    //fileObj will return the original file name, so use response instead.
    $('#image_thumbnail').attr('src', response).show();
  }

I hope that helps someone and saves them the time it took me to figure it out!