Solved

Create a directory with blank index file in it using php

Posted on 2011-09-22
2
213 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
ID: 36581677
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
ID: 36581694
update - the [ b ] are not supposed to be there

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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP installation issues 11 61
Download tables into separate sheets 3 28
two ways encryption with php 3 28
Creating Functions in phpMyAdmin 8 18
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

809 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