<html>
<body bgcolor="white">
<?php
$dirpath = getcwd();
$UPLOAD_PATH = $dirpath."/tmp";
@chdir($UPLOAD_PATH);

/*
 * Iterate over all received files.
 */
echo '<p>';
foreach($_FILES as $tagname=>$objekt)
 {
  // get the temporary name (e.g. /tmp/php34634.tmp)
  $tempName = $objekt['tmp_name'];

  // where to save the file?
  $targetFile = $_POST[$tagname . '_relativePath'];
  // replace '\\' with '/'
  $targetFile=str_replace('\\','/',$targetFile);
  $targetFile=str_replace('//','/',$targetFile);

  // Create folders
  $paths = pathinfo($targetFile);
  mkDirE($paths['dirname']);

  // move the file to the target directory
  if (move_uploaded_file($tempName, $targetFile))
   echo 'Stored: ' . $targetFile;
  else
   echo '<font color=red>Error storing ' . $tempName . ' to ' . $targetFile . '</font>';
  $renmfile = $targetFile; //. "_" . time();
  //@rename($targetFile, $renmfile);
  @chmod($renmfile, 0666);
  echo '<br>';
 }
echo '</p>';

/*
 * Recursively create subfolders
 */
function mkDirE($dir,$dirmode=0777){
 if (empty($dir)) return;
 if (file_exists($dir)) return;
 preg_match_all('/([^\/]*)\/?/i', $dir,$atmp);
 $base='';
 foreach ($atmp[0] as $key=>$val)
 {
  $base=$base.$val;
  if(file_exists($base)) continue;
  if (!mkdir($base, $dirmode))
   {
    echo 'Error: Cannot create '.$base;
    return;
   }
 }
 return;
}
?>
</body>
</html>