Currently seeking new career opportunities in web development, particularly with Laravel, Hire Me

Change file permissions dynamically with php

David Carr

Tutorials PHP & MySQL

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.

function changePermissions($path,$modlevel){

Then using the command chmod we change the file permissions.

chmod($path,$modlevel);

Then do an if statement to see if it's worked or failed this is optional

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

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.

Laravel Modules Your Logo Your Logo Your Logo

Become a sponsor

Help support the blog so that I can continue creating new content!

Sponsor

My Latest Book

Modular Laravel Book - Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Learn Laravel with Laracasts

Faster Laravel Hosting

© 2006 - 2024 DC Blog. All code MIT license. All rights reserved.