Problem with PHP mkdir function on Windows

I am working on the command line in PHP and I am having problems, my first problem is when I call mkdir() PHP, it gives me this error

 Warning: mkdir(): No such file or directory in E:\Server\_ImageOptimize\OptimizeImage.php on line 196 

Then I read in the PHP docs a user comment saying that the forward slash / does not work with this method on Windows, but on Unix.

So, I changed my code to change them to a backslash, but that didn’t change anything for me, I still got the same error on the same line.

Here is the code below can someone help me figure this out please

 // I tried both of these below $tmp_path = '\tmp\e0bf7d6'; //$tmp_path = '/tmp/e0bf7d6'; echo $tmp_path; mkdir($tmp_path); 
+6
source share
2 answers

The actual problem is that mkdir() only creates one subdirectory for each call, but you passed it a path from two non-existent directories. Usually you need to do this step by step:

 mkdir("/tmp"); mkdir("/tmp/e0b093u209"); mkdir("/tmp/e0b093u209/thirddir"); 

Or use the third parameter shortcut:

 mkdir("/tmp/e0b093u209", 0777, TRUE); 
+8
source

I usually use the following line as a constant, and I put in a global file that will be used through my sites.

 defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR); 

This should fix the delimiter problem. I would also try the recursive property found in mkdir that will allow you to create a nested structure. Please see Foillowing, http://php.net/manual/en/function.mkdir.php

You will notice that you need to call mkdir as shown below.

 mkdir ($path, $mode, true) 
+3
source

Source: https://habr.com/ru/post/905553/


All Articles