1

Here's my code; I've renamed the directories, obviously. ;)

$thepath = "/var/www/vhosts/sub.domain.co.uk/web/apps/storage/".$userclient."/evidence/".$scid."/".$doctype."/";
$testdir = is_dir($thepath); 
if ($testdir == false) {
    mkdir($thepath, 0777);
}

In this case, the following variables apply;

$userclient = '000';
$scid       = '9263';
$doctype    = 'Insurance Policy';

So, the path should be;

/var/www/vhosts/sub.domain.co.uk/web/apps/storage/000/evidence/9263/Insurance Policy/

I know this works, EVERYWHERE else in my code, I have other applications using an almost identical setup. But the one above, appears to be tripping up on /evidence/ - it sets the permissions to 755, but will then create the directories per time I run the code, if I set evidence to 777 (Octal).

I get the following error message using;

if (!@mkdir($thepath)) {
    $error = error_get_last();
    echo $error['message'];
}
mkdir(): No such file or directory

Any help would be greatly appreciated, I have to finish this application by Thursday - and this file upload part is the last bit!

Thank you!

Rob Milnes
  • 13
  • 1
  • 4
  • Chances are its falling over on the space.... – BugFinder Sep 25 '12 at 09:19
  • There's no chance of that, the paths in other areas of code operate perfectly, and work perfectly - which also have spaces in (URL readbacks replace spaces with %20 - which is fine ^^) – Rob Milnes Sep 25 '12 at 09:38
  • But your PHP code doesnt turn the space to %20.. I would personally backslash escape the space. – BugFinder Sep 25 '12 at 09:39
  • Thanks for the comments BugFinder, I have it working now based on setting recursive. I've used spaces in directories for years and it's always worked fine, so i've never bothered with extra bits ;P – Rob Milnes Sep 25 '12 at 09:51

2 Answers2

3

PHP can't find directory in which you want to create other directory.

You need to set $recursive param as true:

mkdir($thepath, 0777, true);
Daniil Ryzhkov
  • 7,416
  • 2
  • 41
  • 58
  • But the code works perfectly else where, it creates the directories no problem, one directory short. Where '000/evidence/9263/Insurance Policy/' would be, elsewhere it creates '000/subimages/9263/picture.jpg' no problem. :/ – Rob Milnes Sep 25 '12 at 09:29
  • @Daniil, while the suggestion to set recursive to true is valid, the code you propose sets local variable `$recursive` to true and passes it as a mode. – Michael Krelin - hacker Sep 25 '12 at 09:34
  • Didn't work with php for a while. How is it possible to set keyword argument in php? – Daniil Ryzhkov Sep 25 '12 at 09:38
  • 1
    Is it even possible? I think it's just the third parameter (see my answer). But it doesn't matter, you've got your answer accepted, anyway ;) – Michael Krelin - hacker Sep 25 '12 at 09:53
  • @Michael Krelin - hacker, looks like this is really not possible (http://stackoverflow.com/questions/7704339/can-php-functions-have-keyword-arguments-like-python). Sorry, fixed my answer – Daniil Ryzhkov Sep 25 '12 at 10:40
0

Maybe you want to try mkdir($path,$mode,true) to create missing links as well?

Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173