[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Create a directory with blank index file in it using php

Hi,
I have an app I'm working on that needs to create a directory if it doesn't already exist AND put a blank index.html file into it to keep from allowing the directory contents to be browsed.

My code for the directory is below and works fine. Can it be combined to incorporate writing the index file into it as well? Or is there a better way?

 
if (file_exists($_SERVER['DOCUMENT_ROOT']."/app/application/modules/account/recordings/$account_id")){
	null;
} else {
	mkdir("../recordings/$account_id", 0755);
}

Open in new window

0
tjyoung
Asked:
tjyoung
  • 2
1 Solution
 
amiguraCommented:
if (file_exists($_SERVER['DOCUMENT_ROOT']."/app/application/modules/account/recordings/$account_id")){
	null;
} else {
	mkdir("../recordings/$account_id", 0755); 
[b]file_put_contents("../recordings/$account_id/'index.html", 'hello');[/b]
}

Open in new window


or put a htaccess file in the recordings dir

filename .htaccess
contents in side file Options -Indexes
0
 
amiguraCommented:
update - the [ b ] are not supposed to be there

file_put_contents("../recordings/$account_id/index.html", 'hello');
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now