Hello Guys,

This is about file uploading. When i use the code below, it copies the file to the "storage" folder i manually created on the server. No problem on that.

Code:
<?php
// Your file name you are uploading
$filename = $HTTP_POST_FILES['ufile']['name'];

$file_ext = substr($filename, strripos($filename, '.'));

echo $file_ext;

$new_file_name='NewFile'.$file_ext;

echo $new_file_name;


$path= "storage/".$new_file_name;


if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";

//$new_file_name = new file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file


echo "File Name :".$new_file_name."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";

}
else
{
echo "Error";
}

}
?>

Now here is my problem, After creating a folder and a subfolder based on a users input on a textbox, I applied the copy script above which i thought will also work but it did not copy the file to the folder i want to.

Code:
<?php
$FileTitle = $_POST['txtTitle'];
$Version = $_POST['txtVersion'];
$FullFileName = $_POST['txtCtrl'];

if(is_dir('Storage/'.$FileTitle)==1)
{
  
}
else
{
      //Make Directory
      $thisdir = getcwd(); 
      $dir_path = $thisdir ."/storage/". $FileTitle;
      if(mkdir($dir_path, 0777))
      {
               //echo $dir_path;
               //Create the Version Folder
               $dir_path = $dir_path ."/". $Version;
               if(mkdir($dir_path, 0777))
               {         
                  
                  $filename = $HTTP_POST_FILES['ufile']['name'];

                  $file_ext = substr($filename, strripos($filename, '.'));

                  $new_file_name=$FileTitle.$Version.$file_ext;

                  $path= "storage/". $FileTitle ."/". $Version."/" .$new_file_name;

                  if($ufile !=none)
                  {
                                 if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
                                 {
                                 echo "Successful<BR/>";
                                 }
                                 else
                                 echo "Error";
                  }


               }
               else
               echo "Failed to create [". $dir_path ."] directory.";
      }     
      else
      echo "Failed to create [". $dir_path ."] directory.";
}


?>
The highlighted text is the function and it always goes to the "Error". Is there something i have done or something i have missed?