With this solution there will always be a maximum of 10 files (id's) in each directory
With files (id's) ranging from 1 to 1999 the directories in the root will look like this:

create path for an ID
require_once 'File_structure.php';
for($i=1; $i<2000; $i++){
$File = new File_structure();
$File->id = $i;
$File->prepend_path = 'image/';
$path = $File->create();
file_put_contents($path.$i, 'sd');
}
get path for an ID
require_once 'File_structure.php';
$id = 1254;
$File = new File_structure();
$File->id = $id;
$File->prepend_path = 'image/';
$path = $File->get();
if(is_file($path.$id)){
echo 'ok';
}
class
class File_structure {
public $id;
public $prepend_path = '';
private $path = array();
function get(){
$this->path();
return $this->prepend_path.(substr($this->prepend_path, -1) == '/' ? '':'/').implode('/', $this->path).'/';
}
function create(){
$this->path();
$path = substr($this->prepend_path, -1) == '/' ? substr($this->prepend_path, 0, -1):$this->prepend_path;
foreach($this->path as $dir){
$path .= '/'.$dir;
if(!is_dir($path)){
mkdir($path);
chmod($path, 0777);
}
}
return $path.'/';
}
function path(){
$this->prepare_id();
$length = strlen($this->id);
for($i=0; $i<$length; $i++){
$len = $length - $i;
if($len <= 1){
break;
}
if($path = (int)str_pad($this->id[$i], $len, 0, STR_PAD_RIGHT)){
$this->path[] = $path;
}
}
}
function prepare_id(){
$this->id = (string)$this->id;
}
}