Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Create a directory with blank index file in it using php

Posted on 2011-09-22
2
Medium Priority
?
222 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 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