Php: Iterate over dir path and create folder if not exist [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to make sure each folder in path exist.
$Path = "NamFdr1/NamFdr2/NamFdr3/NamImj.jpg"
E.g.:
First check that "NamFdr1" exists, if not create it;
Then check that "NamFdr2" exists, if not create; and so on.
How can I do this with built-in functions?

try this,
if (!file_exists('NamFdr1/NamFdr2/NamFdr3'))
{
mkdir('NamFdr1/NamFdr2/NamFdr3', 0777, true);
}
i hope it will be helpful

Related

Creating file 'php' after getting data [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
. I wonder how can my project automatically create php file by itself , after getting some data like product description ?
Like you'd create any other file. From the manual. Just give it a .php extension.

I want to create a folder navigation in PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i want to create a data browser where i can navigate through data based on a apache and Mysql server. How can i list data form a selected folder? is this possible in PHP?
Thank you!
Listing folder contents can be done in numerous ways using PHP, from a very simple glob() cmd to a complicated(?) recursiveIterator.
Example of glob.
----------------
$dir=realpath( $_SERVER['DOCUMENT_ROOT'] . '/path/to/folder' );
$col=glob( $dir . '/*.*' );
print_r( $col );

PHP - Find File in Directory By File Name [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a directory full of filenames that contain unix timestamps.
file_1434320602.data
file_1434320352.data
file_1434320112.data
file_1434320032.data
How would I get about loading them up in PHP so that I can select the one which I needed?
There are many ways you can do it. The simplest in this case is glob:
$files = glob('/path/to/file_*.data');
print_r($files);

If Current Domain is X, Then Include [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to use some basic code to include a file if the current domain is http://example.com
How do I do this?
if (...){
include("../clicky.php");
}
$_SERVER can help in many ways
if($_SERVER['HTTP_HOST']=="example.com")
{
include("whatever");
}

generate directory on register in php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I was wondering how I could create a new directory for each user that registered to my site so that they would be able to upload their material to their own directory. I've looked all over the place but haven't really found anything that I could use, because I need it to be dynamic, and I've only found how to name the directory by specifying the name in mkdir.
Thanks in advance.
Say $user contains username of the user this will do the work.
$user = "youruser";
if (!file_exists("path/to/".$user)) {
mkdir("path/to/".$user, 0755, true);
}
be careful about permissions and input sanitization.
Use mkdir function : mkdir("some/path/{$username}", 0755);

Categories