php - Insert image file path into PostgreSQL database -
i have mobile application sends data php web service. data consists of textual items , base64 encoded string (which decoded image).
i want store textual data data columns , final text column containing file path uploaded image. have directory called usersimages/
, store images received user, when upload data, php script doesn't insert database.
php file:
$conn = pg_connect("database_credentials"); /* 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 records (name, description, latitude, longitude, project, imagepath) values ('$s_name', '$s_desc', '$latitude', '$longitude', '$project', '$file')");
what want do:
i want data stored text final column imagepath
containing path image have uploaded, i'm having no success @ moment. ideas?
i believe problem running "imagepath" column storing $file variable fopen('usersimages/test.jpg', 'wb');
. cannot store function call column cell, instead should presumably storing data-type suit needs (since want store path-string varchar should work fine).
what assume store path instance:
$filepath = "usersimages/test.jpg"; $res = pg_query("insert records (name, description, latitude, longitude, project, imagepath) values ('$s_name', '$s_desc', '$latitude', '$longitude', '$project', '$filepath')");
(as long connected database method should work)
might further suggest store variable name save space , hardcode variables same.... instance if folder same , image type jpg can store $filepath = "test";
, change loading code hard-coded variables , not database query.
as other question uploading image website, difficult tell exact answer because did not provide relevant code; looks getting false file due improper uploading technique. should try instead of fopen,fwrite,fclose method.
<input type="file" name="file" id="file"> // in form (seperate php) $filepath = "userimages/test.jpg"; //setting file path $success = move_uploaded_file($_files['uploaded_file']['tmp_name'], $filepath); //actually storing file file-system selected path
Comments
Post a Comment