Programmatically attach existing images with existing node.

Sometimes you have requirement to attach existing images with some existing node. Now there is two either you upload images manually for each node or create a small snippet that do this work for you. So here is a small snippet that do the similar thing with less code, you can easily iterate this for multiple load also.

In this example I am associating multiple existing images with one node i.e nid is 2.