fopen alternative

前端 未结 1 1626
闹比i
闹比i 2021-01-19 09:34

I\'ve got an simple php script, wich creates a file, add some content and closes it again. But my host disabled the fopen function. I was wondering how I could get around th

相关标签:
1条回答
  • 2021-01-19 10:27
    //to write    
    file_put_contents('path_and_filename','content');
    //to read:
    file_get_contents('path_and_filename');
    

    If you want to append to the file:

    file_put_contents('path_and_filename' , 'content' , FILE_APPEND );
    

    You can also lock the file:

    file_put_contents('path_and_filename' , 'content' , LOCK_EX );
    

    Take a look at the links below:

    http://php.net/manual/en/function.file-put-contents.php

    http://php.net/manual/en/function.file-get-contents.php

    0 讨论(0)
提交回复
热议问题