Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 783 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create a folder if it doesn't already exist

#1
I've run into a few cases with WordPress installs with [Bluehost][1] where I've encountered errors with my WordPress theme because the uploads folder `wp-content/uploads` was not present.

Apparently the Bluehost [cPanel][2] WordPress installer does not create this folder, though [HostGator][3] does.

So I need to add code to my theme that checks for the folder and creates it otherwise.

[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]


Reply

#2
if (!is_dir('path_directory')) {
@mkdir('path_directory');
}
Reply

#3
This is the most up-to-date solution without error suppression:

if (!is_dir('path/to/directory')) {
mkdir('path/to/directory');
}
Reply

#4
$upload = wp_upload_dir();
$upload_dir = $upload['basedir'];
$upload_dir = $upload_dir . '/newfolder';
if (! is_dir($upload_dir)) {
mkdir( $upload_dir, 0700 );
}
Reply

#5
You first need to check if directory exists `file_exists('path_to_directory')`

Then use `mkdir(path_to_directory)` to create a directory

mkdir( string $pathname [, int $mode = 0777 [, bool $recursive = FALSE [, resource $context ]]] ) : bool

More about [mkdir() here][1]

Full code here:

$structure = './depth1/depth2/depth3/';
if (!file_exists($structure)) {
mkdir($structure);
}


[1]:

[To see links please register here]

Reply

#6
Here you go.

if (!is_dir('path/to/directory')) {
if (!mkdir('path/to/directory', 0777, true) && !is_dir('path/to/directory')) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', 'path/to/directory'));
}
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through