I'm having trouble with uploading an image to my local server. I test it in POSTMAN
.
I doubt it is my $path
that causes the error.
My upload.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 = 'C:/Users/Luffy/Documents/XAMPP/htdocs/images/'.$image_name;
$file = fopen($path, 'wb');
$is_written = fwrite($file, $decoded_string);
fclose($file);
if($is_written > 0) {
$connection = mysqli_connect('localhost', 'root', 'password','photos');
$query = "INSERT INTO photos(name,pathFile) values('$image_name','$path');";
$result = mysqli_query($connection, $query) ;
if($result){
echo "success";
}else{
echo "failed";
}
mysqli_close($connection);
}
}
How do I exactly map folders in Xammp? I tried getting $_SERVER['DOCUMENT_ROOT']
but it doesn't working.