doesn’t look like you $target_path
is a valid directory. you need to replace the url you have there with the actual directory to which it is mapped to on the server, and make sure you have the permissions to write to that directory. (-1 the question because it is not truly related to WordPress)