问题
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