[thelist] Grrrrrr mkdir() php help needed

Rob Smith rob.smith at THERMON.com
Fri Jul 30 11:03:15 CDT 2004


Hey,

I'm doing some testing here on the mkdir function and I went to php.net to
read up on the documentation. my input data is:

<input type="file" name="userfile">

Then I hop over to my insertdata.php file where I found the following code:

function mkdir_p($target)
{
  if (is_dir($target)||empty($target)) return 1; // best case check first
  if (file_exists($target) && !is_dir($target)) return 0;
  if (mkdir_p(substr($target,0,strrpos($target,'/'))))
    return mkdir($target); // crawl back up & create dir tree
  return 0;
}
// Returns 1: when dir already exists, or successfully made
// Returns 0: when anything contrary to above
			
$uploaddir = '/export/.../uploads/' . $sub_folder . '/'; //where ... is the
entire file path and $sub_folder is my "username" according to my
registration. This is the spot I'm going to upload my files to and manage
disk quota along with my personalized file management system.
$uploadfile = $uploaddir . $_FILES['userfile']['name'];
			
mkdir_p($uploaddir);

Ok. The recursive code works well, but all for the fact that once it
actually creates the folder. I get an error message:

Warning: mkdir(/export/.../uploads/rsmith/): File exists in
/export/.../InsertData.php on line 107
// once again where ... is my huge long file path.

...great! But for heaven sakes don't tell me. Just do it as I have a
header("Location: ../"); following immediately after. I don't want anything
written on the screen. 

Can you help?

Rob Smith


More information about the thelist mailing list