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! While you're at it, check out some resources Treehouse students have shared here.
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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Denny Schouten](https://secure.gravatar.com/avatar/d57876c89c5a9bd71db8c353a35ac631?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Denny Schouten
8,246 Pointswriting-csv what is wrong with my code? Permission denied
What it suppose to do is to add a line in the people.csv (location root/data/csv/people.csv) from the form(see below) however I get the Warning: fopen(../data/csv/people.csv): failed to open stream: Permission denied in /home/treehouse/workspace/inc/write_csv.php on line 11 line 11 is if (($fh = fopen('../data/csv/people.csv', 'a+' )) !== false) { Please halp!?
this is my write_csv.php file, location root/inc/write_csv
<?php
$new_person = [
filter_input(INPUT_POST, 'first', FILTER_SANITIZE_STRING),
filter_input(INPUT_POST, 'last', FILTER_SANITIZE_STRING),
filter_input(INPUT_POST, 'website', FILTER_SANITIZE_URL),
filter_input(INPUT_POST, 'twitter', FILTER_SANITIZE_STRING),
filter_input(INPUT_POST, 'img', FILTER_SANITIZE_URL)
];
if (($fh = fopen('../data/csv/people.csv', 'a+' )) !== false) {
fseek($fh, -1, SEEK_END);
if (fgets($fh) != PHP_EOL) {
fputs($fh, PHP_EOL);
}
fputcsv($fh, $new_person);
fclose($fh);
}
header('location: /people.php');
this is the add_person.php page, location root
<?php
/**
* Form for adding more people to the csv file
* first,last,website,twitter,img
*/
$title = 'Add Person';
require 'inc/header.php';
?>
<form method="post" action="inc/write_csv.php">
<div class="form-group input-group-lg">
<label class="control-label" for="first">First Name</label>
<input class="form-control" type="text" name="first" id="first" />
</div>
<div class="form-group input-group-lg">
<label for="last">Last Name</label>
<input class="form-control" type="text" name="last" id="last" />
</div>
<div class="form-group input-group-lg">
<label for="website">Website</label>
<div class="input-group input-group-lg">
<span class="input-group-addon" id="website-addon">http://</span>
<input class="form-control" aria-describedby="website-addon" type="text" name="website" id="website" />
</div>
</div>
<div class="form-group input-group-lg">
<label for="twitter">Twitter</label>
<div class="input-group input-group-lg">
<span class="input-group-addon" id="twitter-addon">@</span>
<input class="form-control" aria-describedby="twitter-addon" type="text" name="twitter" id="twitter" />
</div>
</div>
<div class="form-group input-group-lg">
<label for="img">Image</label>
<input class="form-control" type="text" name="img" id="img" placeholder="http://" />
</div>
<button class="btn-lg btn-default" type="submit"><?php echo $title; ?></button>
</form>
<?php
require 'inc/footer.php';
![Clare A](https://uploads.teamtreehouse.com/production/profile-photos/5367692/micro_2015-09-04_15.51.30.jpg)
Clare A
23,994 PointsI'm having the same issue. I went back and looked at the notes on file permissions then checked it using fileperms() - the response was "rw-r--r--" - so that suggests that I do have read and write permission (unless I'm not the owner??). Nevertheless I tried updating it anyway using chmod() as Victoria suggests. Result was "chmod(): Operation not permitted".
Hoping someone chimes in with an answer :-(
1 Answer
![Darrell Conklin](https://secure.gravatar.com/avatar/78ca4a41bd13b2fdbb9c15d4ae19cfb8?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Darrell Conklin
22,098 PointsUsing your console type the following command
chmod 777 data/csv/people.csv
![Alena Holligan](https://uploads.teamtreehouse.com/production/profile-photos/1539972/micro_alena-holligan.jpg)
Alena Holligan
Treehouse TeacherI have updated both the workspace and the Teacher's notes in case people still have issues
Victoria Loisi
7,070 PointsVictoria Loisi
7,070 PointsHi there! Have you tried changing the permissions of the csv file before fopen()? Have a look at: http://php.net/manual/en/function.chmod.php Hope it helps!