Try to always use the absolute path, as it was in your second example, which works.
Of course, you do not want to hard code this physical path, so you will want to use either:
dirname(__FILE__)to get the path to the directory that contains the file in which it is written- PHP >= 5.3:
__DIR__, .
, , , - :
$postcontent['files'] = '@' . __DIR__ . '/test.jpg';
, PHP < 5.3:
$postcontent['files'] = '@' . dirname(__FILE__) . '/test.jpg';