snipt

Ctrl+h for KB shortcuts

PHP

Makes directory if it doesn't exist

1
2
3
4
// The following line if you want to make the directory if it doesn't exist
$targetPath = YOUR TARGET PATH
if(!file_exists(str_replace('//','/',$targetPath))) {						mkdir(str_replace('//','/',$targetPath), 0775, true);
}
https://snipt.net/embed/e1b564d05b227faa4506c52302a9cdae/
/raw/e1b564d05b227faa4506c52302a9cdae/
e1b564d05b227faa4506c52302a9cdae
php
PHP
4
2019-08-24T01:09:45
True
False
False
/api/public/snipt/28426/
makes-directory-if-it-doesnt-exist
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">// The following line if you want to make the directory if it doesn&#39;t exist</span> </span><span id="L-2"><a name="L-2"></a><span class="x">$targetPath = YOUR TARGET PATH</span> </span><span id="L-3"><a name="L-3"></a><span class="x">if(!file_exists(str_replace(&#39;//&#39;,&#39;/&#39;,$targetPath))) { mkdir(str_replace(&#39;//&#39;,&#39;/&#39;,$targetPath), 0775, true);</span> </span><span id="L-4"><a name="L-4"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
php