Однолинейное решение
<?
$filename="test.php";
$filename=str_pad(trim($filename), 10, "123456789", STR_PAD_LEFT);
echo $filename;
//12test.php
$filename="test.php";
$filename=str_pad(trim($filename), 14, "123456789", STR_PAD_LEFT);
echo $filename;
//123456test.php
?>