由mkdir()创建的文件夹不可访问

I'm using mkdir() inside a foreach loop to create my folders:

if (!file_exists($id))
{
    mkdir($id);
}

$id could be 529e1f4070b0c

Folders are created but when accessing them by FTP or directly from Direct Admin file manager, I encounter No such file or directory, also a 404 Not found page when accessing through browser.

What's wrong?

#Update 1

I removed foreach loop and assigned $id manually that works well, folder created and is accessible, but when it's inside foreach, folders are created but not accessible!

#Update 2

I changed the code to use full path as recommended in comments:

if (!file_exists(dirname(__FILE__)."/".$id))
{
    mkdir(dirname(__FILE__)."/".$id, 0777);
}

Which also leads to previous results!

#Update 3

Complete code of block:

$file = file("codes.txt");
foreach ($file as $id)
{
    $html = content_of_url($id);
    if (!file_exists(dirname(__FILE__)."/".$id))
    {
        mkdir(dirname(__FILE__)."/".$id, 0777);
    }
    $dom = new domDocument;
    $dom->loadHTML($html);
    $dom->preserveWhiteSpace = false;
    $images = $dom->getElementsByTagName('img');
    foreach ($images as $i => $img)
    {
        $url = str_replace("../..", "http://domain.com", $img->getAttribute('src'));
        file_put_contents(dirname(__FILE__)."/".$id."/".$i.".jpg", file_get_contents($url));
    }
}

Use the below

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

Assume you are creating folder inside a 'ID FOLDER' folder

then specify the path too

if (!is_dir('ID FOLDER'.$id))
{
    mkdir('ID FOLDER'.$id,0777);
}

try to set permissions :) and set recursive = true

$path = "folder/path/where/files/should/be/stored/";
mkdir($path , 0777, true);

DON'T give Filename with it... first create Path, than File

$handle = fopen( $path . "essource.txt", "r");

you may need to replace / with \\

change the permission, this might help

Try to use backslashes under Windows or use the constant DIRECTORY_SEPARATOR in the path. And also you can try to change the permission.

You need to set permission on the folder to be accessed by "non apache" users. Use the chmod instruction. http://www.php.net/chmod

After creating the folder try to change the folder permission with chmod().