Solution 1 :
As the warning
1) PHP Warning: file_put_contents(images/before_3.png): failed to open stream: Permission denied in C:inetpubwwwroottgotworker_testingandroid2task_update_before.php on line 22
clearly states, the user that’s running the PHP script does not have the rights to
access that images/before_3.png
file. I’m not super familiar with PHP on Windows but I would suggest running the script with administrator rights.
Problem :
Currently I created an android system that can snap a photo from the camera and save it to Microsoft SQL database. When I uses localhost (XAMPP), the image successfully store at the folder “images” and the link created and save to the MySQL database.
But when I want to change to Microsoft SQL Server 2016, the image that capture is not saved at the folder “images” but the link is created and save to the Microsoft SQL database. The error that found is at the PHP side, below is the error:
1) PHP Warning: file_put_contents(images/before_3.png): failed to open stream: Permission denied in C:inetpubwwwroottgotworker_testingandroid2task_update_before.php on line 22
and below is the php code:
<?php
require_once "../config/configPDO.php";
$defID = 0;
$photo_before = $_POST['photo_before'];
$report_id = $_GET["report_id"] ?? "";
$stmt = $conn->query("SELECT * FROM ot_report ORDER BY report_id ASC");
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$defID = $row['report_id'];
}
$defID = "before_" . $defID;
$imgPath = "images/$defID.png";
$ServerURL = "http://172.20.0.45/tgotworker_testing/android2/$imgPath";
$sql = "UPDATE ot_report SET photo_before ='$ServerURL', time_photo_before = GETDATE(), ot_start = '16:00:00' WHERE report_id = '$report_id'";
$query = $conn->prepare($sql);
$query->execute();
if($query){
file_put_contents($imgPath,base64_decode($photo_before)); //line 22
echo "Data Save!";
}else{
echo "Error!! Not Saved";
}
?>
Can anyone help me to solve this problem? Thanks.
Comments
Comment posted by Peter Davidson
@can i know how to run the script with administrator?
Comment posted by mrodo
How are you running the script normally, in the first place? From that we can figure out how to do the same as admin.