2
When trying to create a file in JSON format with fopen
I am returned a permission error with the following message:
Warning: fopen(/json/9.json): failed to open stream: No such file or directory in C: xampp htdocs apil Controllers Classex.php on line 120
As I use Windows OS I have also already given permission in the folder I have already left pre-created, however the problem still persists.
Permission I gave everyone about the JSON file by right-clicking on the file->Properties->Share:
The code I’m using to create the file and then write the data to it follows:
protected function filejson($product_id, $account_id) {
$file = array($account_id);
$json = fopen("/json/" . $product_id . ".json", "w");
fwrite($json, json_encode($file));
fclose($json);
}
And make the call of the method in another method that is in the same class as follows:
Classex::filejson($product_id, $this->getAccount_id());
It is worth mentioning that both vestments $product_id
and $account_id
have the correct content or are not null.
I am using XAMPP in Windows 10.
Thanks in advance for the attention Bacco, But the same error still persists even implementing $_SERVER , will be that the error may be a problem in XAMPP?
– Thiago Drulla
Just to complement my last comment , when using $_SERVER basically it returns me the same error with the exact path of the file "fopen(C:/xampp/htdocs/json/14.json): failed to open stream: No such file or directory in ..."
– Thiago Drulla
Probably error on the way, try the full path for test purposes in format
$json = fopen('C:/xampp/htdocs/json/9.json')
for a fixed and existing test JSON. Take advantage of and view the error log if you have no base restriction or similar– Bacco
Is it sure the path is the same? Have you checked the folder permissions for the page server user? json does not need to exist, which PHP creates, but the folder path does not.
– Bacco
Note that SHARE is not folder permission. Folder permission is in the security part.
– Bacco
I checked again and actually the file path was looking for the json folder in the htdocs folder and the correct one was the path
$root/apil/Controllers/json/
.&#Thank you very much for your attention Bacco!– Thiago Drulla
Good that solved, just note the issue of sharing, undo it to not have undue access to the source file over the network
– Bacco
blz , I’ll be back to the default setting.
– Thiago Drulla