?
Solved

Create a directory with blank index file in it using php

Posted on 2011-09-22
2
Medium Priority
?
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 dynamically set the form action using jQuery.
Suggested Courses

800 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