Since I guess this was the solution I'll post it as answer.
I think you want "tmp/" . $a . ".png"
instead of "/tmp/" . $a . ".png"
. It's good practice to just always use absolute paths, so: __DIR__ . "/tmp/" . $a . ".png"
. This takes away any confusion.