05May2011
Change file permissions dynamically with php Thumbnail

Change file permissions dynamically with php

A tutorial to change file permissions dynamically with php

A tutorial to change file permissions dynamically with php

first define the function name in this case call it change Permissions with two parameters $path is the path to the folder and $modlevel is the permissions level to use.

<?php
function changePermissions($path,$modlevel){
?>

Then using the command chmod we change the file permissions

<?php
chmod($path,$modlevel);
?>

then do an if statement to see if it’s worked or failed this is optional

<?php
if(chmod){
  echo "success";
} else {
  echo "failed";
}
?>

to run the function you need to call it, you call it by typing it’s name with the parameters

<?php
changePermissions("assets/images/uploads/",777);
?>

here’s the full script:

<?php
function changePermissions($path,$modlevel){
chmod($path,$modlevel);
if(chmod){
  echo "success";
} else {
  echo "failed";
}
}
 
changePermissions("assets/images/uploads/",777);
?>

That’s it now you should be able to change file permissions dynamically with php.

Author
Dave

About the Author

has written 72 articles on Dave is my name.

My name is David Carr I'm a PHP web developer based in Hull it is my passion to design and develop clean, accessible and usable websites using PHP and other web technologies, I'm an avid Twitter user why not follow me? https://twitter.com/daveismynamecom

Visit this author's website   ·   View more posts by

Sharing is caring.
  • Subscribe to our feed
  • Share this post on Delicious
  • StumbleUpon this post
  • Share this post on Digg
  • Tweet about this post
  • Share this post on Mixx
  • Share this post on Technorati
  • Share this post on Facebook
  • Share this post on NewsVine
  • Share this post on Reddit
  • Share this post on Google
  • Share this post on LinkedIn

Discussion

No responses to "Change file permissions dynamically with php"

There are no comments yet, add one below.

Leave a Comment