I have a mobile application that sends some data to my PHP web service. The data consists of some textual items and a base64 encoded string (which will be decoded into an image).
I want to store the textual data into some data columns and then a final text column containing the file path to the uploaded image. I have a directory called usersImages/, which is where I would like to store all images received by the user, but when I upload the data, my PHP script currently doesn't insert anything into the database.
PHP file:
$conn = pg_connect("database_credentials");
/* GET DATA */
$name = $_POST['name'];
$s_name = pg_escape_string($name);
$description = $_POST['desc'];
$s_desc = pg_escape_string($description);
$latitude = $_POST['lat'];
$longitude = $_POST['lng'];
$project = $_POST['project'];
$encoded_photo = $_POST['snap'];
echo $encoded_photo;
$photo = base64_decode($encoded_photo);
header('Content-Type: bitmap; charset=utf-8');
$file = fopen('usersImages/test.jpg', 'wb');
fwrite($file, $photo);
fclose($file);
$res = pg_query("INSERT INTO records (name, description, latitude, longitude, project, imagepath) VALUES ('$s_name', '$s_desc', '$latitude', '$longitude', '$project', '$file')");
What I want to do:
I want all the data to be stored as text with the final column imagepath containing the path to the image I have just uploaded, but I'm having no success with this at the moment. Any ideas?