PHP snippet to create image gallery from folders with jpgs
Is PHP_EOL the best way to add a newline character in order to make the output HTML look better?


No, I don't think so. If you want your HTML nice on output, why not have it nice in the source code as well?

So instead of this:

echo "&lt;div&gt;".PHP_EOL."    &lt;p&gt;".basename($file, ".jpg")."&lt;/p&gt;".PHP_EOL."    &lt;img src='$file' alt='".basename($file, ".jpg")."'&gt;".PHP_EOL."&lt;/div&gt;".PHP_EOL;


have this:

echo "&lt;div&gt;
        &lt;p&gt;".basename($file, ".jpg")."&lt;/p&gt;
        &lt;img src='$file' alt='".basename($file, ".jpg")."'&gt;
      &lt;/div&gt;;



  Have I used any deprecated functions? 


I don't think so. But generally, you can see that yourself, when you enable warnings in development (don't forget to turn them of in production though).


  Would you please offer any tips regarding best practices, or how to make my code look more readable?



You could extract code blocks to functions
You could use more whitespace (eg around .)
You could extract duplicate function calls to well-named variables
have constants such as fixed directory names in as few places as possibly, to make changing it easier


This would give you something like this. It's not perfect, but hopefully a good start:

echo formatHTMLforDirectory('images/otros/');

/**
TODO PHPDoc comment
*/
function formatHTMLforDirectory($basedirectory) {   
    $directories = glob("$basedirectory/*", GLOB_ONLYDIR); 
    $html = "";
    foreach($directories as $directory) {
        $directoryName = basename($directory);
        $html .= "&lt;section id='$directoryName' class='gallery'&gt;
                    &lt;div id='categoryimg'&gt;
                        &lt;p&gt;$directoryName&lt;/p&gt;
                    &lt;/div&gt;
                    &lt;!-- SECTION --&gt;";
        $files = glob("$basedirectory/$directoryName/*.{jpg}", GLOB_BRACE);
        $html .= formatHTMLforFiles($files);
        $html .= "&lt;/section&gt;";
    }
    return $hmtl;
}

/**
TODO PHPDoc comment
*/
function formatHTMLforFiles(array $files) {
    $html = "";
    foreach($files as $file) {
        $filename = basename($file, ".jpg");
            $html .+ "&lt;div&gt;
                        &lt;p&gt;$filename&lt;/p&gt;
                        &lt;img src='$file' alt='$filename'&gt;
                      &lt;/div&gt;";
    }
    return $hmtl;
}


Misc


I always get nervous when data from the outside is echoed unencoded, as it can lead to XSS. If you allow users to upload image files, you are already vulnerable. But even if not, you may allow this in the future, which would make you vulnerable then.
You might want to think about using a templating engine such as twig. Mixing HTML and PHP often leads to hard to read code.