How do I create file on server?

前端 未结 5 1037
情深已故
情深已故 2021-01-03 11:22

Let say I want create file call style.css in /css/ folder.

Example : When I click Save button script will create style.css with content

5条回答
  •  遥遥无期
    2021-01-03 12:04

    is the function you may want to use

    • http://php.net/manual/en/function.fopen.php to open the file
    • http://php.net/manual/en/function.fwrite.php to write your css
    • http://php.net/manual/en/function.fclose.php to close the file

    or use

    • http://php.net/manual/en/function.file-put-contents.php just one command to master them all

    if you fopen the file and the result of the operation is false then you can't write the file (maybe for permissions, maybe for UID mismatch in safe mode)

    file_put_contents (php5 and upper) php calls fopen(), fwrite() and fclose() for you and return false if something id wrong (you should make yourself sure that false is really the boolean value though).

提交回复
热议问题