Solved

Create a directory with blank index file in it using php

Posted on 2011-09-22
2
207 Views
Last Modified: 2012-05-12
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
Comment
Question by:tjyoung
  • 2
2 Comments
 
LVL 7

Expert Comment

by:amigura
Comment Utility
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
 
LVL 7

Accepted Solution

by:
amigura earned 500 total points
Comment Utility
update - the [ b ] are not supposed to be there

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now