Skip to content

Instantly share code, notes, and snippets.

@TimDorand
Created May 29, 2016 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimDorand/ea8332567be35e6231aa8bf50ae84e65 to your computer and use it in GitHub Desktop.
Save TimDorand/ea8332567be35e6231aa8bf50ae84e65 to your computer and use it in GitHub Desktop.
<?php
header('Content-type : bitmap; charset=utf-8');
if(isset($_POST["encoded_string"])){
$encoded_string = $_POST["encoded_string"];
$image_name = $_POST["image_name"];
$decoded_string = base64_decode($encoded_string);
$path = 'images/'.$image_name;
$file = fopen($path, 'wb');
$is_written = fwrite($file, $decoded_string);
fclose($file);
if($is_written > 0) {
$connection = mysqli_connect('timotheefxtim.mysql.db','timotheefxtim','Adminparis96','timotheefxtim');
// $connection = mysqli_connect('localhost', 'root', '','tutorial3');
$query = "INSERT INTO photos(name,path) values('$image_name','$path');";
$result = mysqli_query($connection, $query) ;
if($result){
echo "success";
}else{
echo "failed";
}
mysqli_close($connection);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment