Change file permissions with PHP


PHP is a programming language Backend very powerful and widely used on the web. With this language we can create, modify and delete files, but for this, those files must have the appropriate permissions, read, write, and execute.

On this occasion, starting from the basis that we want to delete a file from the system, we will use the function chmod from PHP (similar to the Linux chmod command) to give the file permissions.

To give all permits to a file from PHP we will use:

< ? php 
     // File to which we will give permissions
     $ file = "myarchive.jpg";
     // We assign all the permissions to the file
     chmod($ file, 0777);
? >

With this, the file has all the permissions and we can delete it.

We can also make the change directly from our ftp client or from our cPanel.

Have you used something similar? Leave us a comment.

Previous Recover password SICOFI
Next Delete files in PHP

1 Comment

  1. 04/09/2020
    Reply

    Hello, although I have not tested your code yet I ask you:
    -I want to create any.csv file in any folder.
    -I do everything known and the file does not appear.
    -I tried countless variants without success.

    Do you know any safe way that works?

    Thank you !!!

Leave a reply

Your email address will not be published. Required fields are marked *