Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Richard Duffy
16,488 PointsHelp!
I am using xammp on my mac book air 2013 (OSX Maverick)
Here is the error: The File Name Is: richard.html Warning: fopen(richard.html): failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/code1/create.php on line 21 Could not open file
2 Answers
Andrew McCormick
17,730 Pointspossible causes are:
- you either don't have permission to write in the directory your writing to
- the directory you are trying to create the new file in, doesn't exists. fopen won't create a directory only a file. If this is the case then you need to use mkdir to create the directory.

Richard Duffy
16,488 PointsThank you, I am trying to create the file using this code:
$file = $_POST['file'];
$ext = $_POST['ext'];
echo "The File Name Is: ".$file,$ext;
$display_block = <<<END_OF_TEXT
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>$file</title>
</head>
<body>
<h1>This file name is: $file,$ext</h1>
</body>
</html>
END_OF_TEXT;
$fileName = "$file$ext";
$fileH = fopen("$fileName", "x")or die("Could not open file");
fclose($fileH);
$file1 = fopen("$fileName", "x");
fwrite($file,$display_block);
fclose($file1);
chmod($fileName, 0777);
?> ```