I create for each user a folder for his images, while checking the existence of the folder as follows:

$filpath = "img/p".$uId; if(file_exists($filepath) == '0'){mkdir("img/p".$uId);} 

The first time a page with this code is accessed, a folder is created, but when it is repeated, it gives an error:

Warning: mkdir() [function.mkdir]: File exists in Z:\home\mysite.loc\www\setting.php on line 40

on line 40 is just a check.

    1 answer 1

    Watch carefully what the file_exists function file_exists .

    • if (file_exists ($ filepath)) {mkdir ('img / p'. $ uId);} - if you set it this way, it does not give an error, but it’s wrong to create a folder when it is already there. - dikardRus
    • Attentively . It returns TRUE or FALSE. 0 it never returns, so the condition is always yours. - Oleg Arkhipov
    • 0 === false - Maksym Prus