title: Weird results with substr and mkdir function in php
body: <p>I have a fileupload with php but that's irrelevant because my real problem is that i have this code:</p>
  
  <pre><code>if (!empty($_FILES)) {
      $tempFile = $_FILES['Filedata']['tmp_name'];
  $real = $_FILES['Filedata']['name'];
  $finfo = pathinfo($real);
  $time = time();
  $rand1 = substr(sha1($real.$time),0,4);
  $rand2 = substr(sha1($real.$time),5,-22);
  $fname = preg_replace("#[^A-Za-z1-9]#","_", $_FILES['Filedata']['name']);
  mkdir(UPLOAD_TO."/".$rand2,0777);
  $targetFile = UPLOAD_TO."/".$rand2."/".$real;
              move_uploaded_file($tempFile,$targetFile);
     $query = $db-&gt;prepare("INSERT INTO files (realname,filename,extension,filesize,rand1,rand2,uppedby,created) VALUES(:real,:filename,:extension,:filesize,:rand1,:rand2,:uppedby,:created)");
  $query-&gt;execute(array(
  ":real" =&gt; $real,
  ":filename" =&gt; $fname,
  ":extension" =&gt; $finfo['extension'],
  ":filesize" =&gt; filesize($tempFile),
  ":rand1" =&gt; $rand1,
  ":rand2" =&gt; $rand2,
  ":uppedby" =&gt; $_SERVER['REMOTE_ADDR'],
  ":created" =&gt; time()
  ));
  
  }
  </code></pre>
  
  <p>THe file is uploaded and i am creating an sha1 hash from the actual timestamp and the real filename. After i am cutting them with <code>substr()</code> but there is the tricky part. The mkdir is creating the directory not with the cutted string but with strange another combinations.
  I don't know what i'm doing wrong. Could you please take a look at it?</p>