Chris
Chris

Reputation: 419

php mkdir s not working

So I have this pretty straight foreword code for creating a dir with the name the user inputs, but it just won't create. The folder I am wanting to create it in is a subfoolder. When i test it locally it works just fine but then on the server there seems to be a problem. Can anyone help me ?

$title = str_replace(" ", "_", $_POST['title']);
if (!is_dir("uploads/".$title)){
        mkdir("uploads/".$title, 0777);

I guess it lies with the path ? But I just couldn't find out why.

Thanx guys

Chris

Upvotes: 0

Views: 119

Answers (2)

Chris
Chris

Reputation: 419

So after checking a few possibilities ( thanx for your help guys ) I realized, that my ftp program wasn't showing the upload folder correctly. Meaning when checking the upload folder via the host server interface the created folder did appear. But when I checked via my ftp program to see if the folder had been created, it wasn't there. So there must be some kind of problem that disables my ftp program from showing the created folder... I have no clue why this happens but nonetheless the code is working like so:

$target = "uploads/".$title; // save to a variable, to not repeat

if (!is_dir($target)) {
        mkdir($target);
        chmod($target, 0777);}

So thanx for the help guys.

Cheers Chris

Upvotes: 0

Yang
Yang

Reputation: 8711

For most hosting providers, you have to provide a full path, not a relative one:

$root = dirname(__FILE__); // or whatever what points to root dir

$target = $root.'/uploads/'.$title; // save to a variable, to not repeat

if (!is_dir($target) {
     mkdir($target, 0777);
}

Upvotes: 1

Related Questions