Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – PHP / SQL: cannot save image at server but successful save image link at SQL database

Posted on November 11, 2022 By

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.

READ  [FIXED] java - How to transfer data from one activity to another using cardviews?
Powered by Inline Related Posts

Android Tags:android, mysql, php, sql, sql-server

Post navigation

Previous Post: [FIXED] android – How to pass data by Back Button, Kotlin
Next Post: [FIXED] Project with external module issue in android studio 3.6

Related Posts

[FIXED] android -constraintLayout how to add elevation to sticky toolbar? Android
[FIXED] android – AndroidRuntime: FATAL EXCEPTION, java.lang.OutOfMemoryError when sending multiple images Android
[FIXED] java – How to call getSupportFragmentManager() from adapter class (which doesn’t extend AppCompatActivity)? Android
[FIXED] api – Unable to add Spotify App Remote SDK library to Android Studio Chipmunk Android
[FIXED] android – A RenderFlex overflowed on Hero Animation – Flutter Android
[FIXED] java – How to use ProgressBar in Android Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is the rising action in Julius Caesar?
  • How do you secure a rope to itself?
  • Does waterproof laminate scratch easily?
  • What makes a building prewar?
  • What can you learn in a month without alcohol?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme