Can't write to 'localhost/choo/tcimages/176801_1.JPG-14660': No such file or directory ... I have no idea what to do here.
Have you checked if there's a directory like that?
Since the pathname is relative, it's relative to whatever the current working directory is when that open executes. Because the working directory can change, normally absolute pathnames are better; if there's a configuration option somewhere that sets the path for these files, you might want to check that it's set to an absolute path rather than a relative one.
As for the code, note the filename is being passed in as $arg, so this particular code doesn't help, you'd have to trace back where $arg is coming from.