PHP and file write permissions

前端 未结 3 1560
一整个雨季
一整个雨季 2020-12-18 08:43

I have a folder with 3 different php scripts in it. email.php txt.php android.php

I pipe emails and/or txts to their respective scripts, and use http POST to send da

3条回答
  •  感动是毒
    2020-12-18 09:25

    Ok, so with the help of everyone who responded, I have worked out a solution: The email and txt scripts are run by user 'owner' and the htmlPOST is run by user '?'

    I had to make the folder chmod 777 in order for user '?' to work

    When each script runs, it checks for the file 'output.php'. If it didn't exist, then after the fclose I added a chmod 777 - that way the scripts run by other users could open/write it later. If the file already existed, then I didn't add the chmod because if it was the wrong user it created an error. So a simple example of it:

    $data = '//data fields condensed into a single string obtained from email or txt';
    $filename= "output.php";
    
    if (file_exists($filename)){
        $newFile= fopen($filename, 'w+');
        fwrite($newFile, $data);
        fclose($newFile);
    } else {
        $newFile= fopen($filename, 'w+');
        fwrite($newFile, $data);
        fclose($newFile);
    
        chmod($filename, 0777);
    }
    

    Thanks for your help!

提交回复
热议问题