how to use php+mysql to decode the image stream and store the stream to database

so i need to add an image into Mysql via php file.. i selet that image from an UWP app : which upload the image a stream .. Now i'm stuck as i don't know what from there .. Here is the Php code i'm using but it's not working as i do find an image.png but it displays nothing .. any help would be appreciated

<?php
 if($_SERVER['REQUEST_METHOD']=='POST'){
  $UserName = $_POST['UserName'];
 $UserImage = $_POST['UserImage'];
 require_once('conn.php');
 $sql ="SELECT  UserId FROM user";
 $res = mysqli_query($connect,$sql);
 $UserId =0 ;
 while($row = mysqli_fetch_array($res)){     
 $UserId = $row['UserId'];
 $UserId = $UserId+1;
 }
 $path = "UserImage/$UserId.png";
 $actualpath = "http://localhost/mydatabase/$path";
 $sql = "INSERT INTO user (UserId,UserName,UserImage) VALUES ('$UserId','$UserName','$actualpath')";
 if(mysqli_query($connect,$sql)){
 file_put_contents($path,base64_decode($UserImage));
 echo "Successfully Uploaded";

 } 
 mysqli_close($connect);
 }else{
 echo "Error";
 }
 ?>

Answers


Check your $actualpath matches with the $path where you uploaded. It seems they are not matching.


Need Your Help

Undefined reference to QGLFormat

c++ qt qtwidgets

I'm trying to compile my QGLWidget object for a simple painting program, but i'm getting some pretty strange errors I can't understand.

CakePHP 2.3 Console Schema: the chosen schema could not be loaded

cakephp cakephp-2.0 cakephp-2.1

I have a number of Plugins for my CakePHP 2.3 app which I use the schema migrations built in to maintain DB table structure.