imagepng is not working with absolute path-php

I am developing api server in that using imagepng it works fine when i give relative path like

imagepng($img, "../".$imageFileName); 

but not works when I give absolute path like

imagepng($img, "http://www.example.com/dev/resource/images/".$imageFileName);

Please suggest me a solution I need to give the absolute path in imagepng()