1

I have a PHP file with code as below with the functionality to save an image in a file directory , after uploading from mobile.

<?PHP
$data = file_get_contents('php://input');
echo $data;
exit ($data);

if (!(file_put_contents($_GET['filename'],$data) === FALSE)) echo "File xfer completed."; // file    could be empty, though
else echo "File xfer failed.";
?>

We dont have much control on the front end side to change , so the logic of storing an image in MY SQL db should be from PHP script.

the $data echo results as below for an image of JPG format http://goo.gl/4AsU52 enter image description here

$data Echo : enter image description here

Now , how do i store the $data value/its relative file directory in php into MYSQL DB?

user3592479
  • 665
  • 3
  • 13
  • 26
  • I did this a while back and compressed/decompressed the string to make it more manageable. Cannot remember the exact method. Maybe something similar to md5() or maybe I used my own. Base64! Thanks what i used! – n00bstacker Jan 13 '15 at 04:46
  • I think you should just store the path of your image instead. In the future your image will be store in your local directory or CDN and you simply reference the path. – Shih-Min Lee Jan 13 '15 at 04:46
  • Note it's not a good idea to store images in a text form in your database (which can take up a good amount of space), it's better just to store it on the server path. Store it in the directory, then store the path as a string in the DB. – Spencer Wieczorek Jan 13 '15 at 04:47
  • Any more inputs ? please suggest me with code – user3592479 Jan 13 '15 at 06:35

0 Answers0