Welcome Guest, Not a member yet? Register   Sign In
mkdir and "file existing"
#1

[eluser]Alhazred[/eluser]
I have to upload files from my application.
According to some form's fields filled by the user, the images must be put in different folders.

Before to upload the images I check if the path to the destination folder exists, if not I create all the missing folders.

The code is like this
Code:
//check if the $name folder exists, if not create it
if( ! is_dir(base_url('static/uploads/'.$name)))
{
if ( ! mkdir('./static/uploads/'.$name,0777))
  return FALSE;
}
  
//check if the $location folder exists, if not create it
if( ! is_dir(base_url('static/uploads/'.$name.'/'.$location)))
{
if ( ! mkdir('./static/uploads/'.$name.'/'.$location,0777))
  return FALSE;
}

return 'static/uploads/'.$name.'/'.$location;
The first time the folders are created, lets say the path is: /static/upload/John/Italy

If now John uploads other pics, he receives an error message like this
Code:
A PHP Error was encountered
Severity: Warning
Message: mkdir(): File exists
Filename: models/images_model.php
Line Number: 22
Where line 22 is the 1st mkdir().

is_dir() returns false even if the folder /static/upload/John exists, so the mkdir() is executed, but the folder is already there.

I've noticed that even if I set 0777 in the mkdir(), the created folders have 0755.
By the way, I've manually changed the permissions to 0777 (I'm on a local Linux machine) and the problem persists.

Is there anything wrong with my is_dir() checks?


Messages In This Thread
mkdir and "file existing" - by El Forum - 07-19-2012, 10:07 AM
mkdir and "file existing" - by El Forum - 07-19-2012, 10:36 AM
mkdir and "file existing" - by El Forum - 07-19-2012, 10:50 AM
mkdir and "file existing" - by El Forum - 07-19-2012, 01:14 PM
mkdir and "file existing" - by El Forum - 07-19-2012, 01:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB