Search code examples
phpfopenpermission-denied

PHP fopen can't create a file


I have a function in PHP language to create an xml file when requested.

if(($file= fopen("./include/catalogo.xml", "w"))==false){echo 'non creo il file'; return false;}

"catalogo.xml" can't be created, permission denied. I know I should try to change permissions, but how can do this if the file doesn't exist? Or, are there things that I ignored?


Solution

  • If you use the terminal and go to the parent of folder your file will be created in, which is the parent of the include folder and type in the command:

    chmod 777 include
    

    This should change the permissions of this folder so you won't receive the permission denied error anymore. If you do try this command:

    chmod -R 777 include