Search code examples
phplinuxdirectory-structure

PHP folder creation (mkdir) fail when using variable with slash in it


I have application with cases ids structured with / in them, example: F-4/1, I am making upload script and making a folder for each case and it is failing on every /.

for F-4/1 it will make F-4 folder.

$prikaz8 ="F-4/1";

if (!file_exists('uploads/'.$prikaz8)) {
    mkdir('uploads/'.$prikaz8, 0777, true);
} 

I tried escaping it but didn't work. I can not find any information on this and how to solve it, please advise.

When I make them manually, I have it mounted over sshfs it lets me create it. I know I can replace / with something else, but I would like to keep case number the same. Would I even be able to target such folder with PHP later after creation?

enter image description here


Solution

  • Linux enviorment "/" used for seperators, hence we cant use it in file Or dir name. there is already answer for it. Kindly refer it this. click here