fopen - failed to open stream: Permission denied

天涯浪子 提交于 2021-01-27 19:26:49

问题


Is it possible to write data to CSV while the file is opened from desktop? Because I am trying to write some input data to CSV when user submit the form, but I am getting above error when the file is opened from my desktop. My system will only write to csv when I close the file.

Error when meeting the line $fp = fopen("C:\Users\lenovo\Desktop\sample.csv", "w");


回答1:


Change the permission of the file sample.csv by using the following command on the terminal in the folder where the file is-

chmod 777 sample.csv



回答2:


<?php       
       $myfile = fopen("C:\Users\lenovo\Desktop\sample.csv", "a+");
        // the variable holding the values
        $numbers;
        // write the variable in the text file created 
        fwrite($myfile, $numbers);
        // close the file when done
        fclose($myfile);
?>

W = Open a file for write only. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file

a+ = Open a file for read/write. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist

I hope it helps



来源:https://stackoverflow.com/questions/45836374/fopen-failed-to-open-stream-permission-denied

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!