saran_singh Posted April 6, 2012 Share Posted April 6, 2012 I am using wampserver 2.2 on window 7 64 bit machine. I am using jpegcam to take snapshots and it works fine. I make upload folder within jpegcam/htdocs/upload to store snapshots. All works fine but how can i store uploaded images into mysql. I also want to retrieve image from mysql and print in php page. The problem is jpegcam used java script in form in which POST method and type file was not used. I am already done task like upload images to folder and store it into mysql using POST an $_FILES varibales . here the code of in jpegcam/htocs/test.html <form name="f1" enctype="multipart/form-data" method="" action="" > <input type=button value="Configure..." onClick="webcam.configure()"> <!-- <input type=button name="img" value="Take Snapshot" onClick="take_snapshot()"> --> <a href="javascript:void(webcam.freeze())">Freeze</a> <a href="javascript:void(webcam.upload())">Upload</a> <a href="javascript:void(webcam.reset())">Reset</a> </form> and this the code of jpegcam/htocs/test.php $target = 'upload/'; $filename = $target . date('YmdHis') . '.jpg'; $result = file_put_contents( $filename, file_get_contents('php://input') ); if (!$result) { print "ERROR: Failed to write data to $filename, check permissions\n"; exit(); } Now please tell me how can i store snapshots in mysql an retrieve it an print it in another php page.please plzplz help me as soon as possibe. please please... Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/260465-how-can-i-store-jpegcam-snapshots-in-mysql-using-php/ Share on other sites More sharing options...
jayjay159357 Posted April 6, 2012 Share Posted April 6, 2012 Cant you do a mysql_query before you move the uploaded file? Quote Link to comment https://forums.phpfreaks.com/topic/260465-how-can-i-store-jpegcam-snapshots-in-mysql-using-php/#findComment-1335028 Share on other sites More sharing options...
jayjay159357 Posted April 6, 2012 Share Posted April 6, 2012 By the way, you can't put an image in a database only the link to the image. Quote Link to comment https://forums.phpfreaks.com/topic/260465-how-can-i-store-jpegcam-snapshots-in-mysql-using-php/#findComment-1335033 Share on other sites More sharing options...
Jessica Posted April 6, 2012 Share Posted April 6, 2012 By the way, you can't put an image in a database only the link to the image. Actually you can, it's just a bad bad idea. Quote Link to comment https://forums.phpfreaks.com/topic/260465-how-can-i-store-jpegcam-snapshots-in-mysql-using-php/#findComment-1335036 Share on other sites More sharing options...
saran_singh Posted April 7, 2012 Author Share Posted April 7, 2012 Thanks to reply everyone... I uploaded snapshots in folder upload and into mysql. Following are the code $target = 'upload/'; $filename = $target . date('YmdHis') . '.jpg'; $result = file_put_contents( $filename, file_get_contents('php://input') ); if (!$result) { print "ERROR: Failed to write data to $filename, check permissions\n"; exit();} $dbconn = mysql_connect("localhost", "root", "") or die(mysql_error()) ; mysql_select_db("jpegcam") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO 'image' VALUES ('$pic')") ; mysql_close($dbconn); ?> The link of snapshots stored successfully in mysql.Now prpblem is how to retrieve it. For retrieve image i written following code:- <?php $dbconn= mysql_connect("localhost", "root", "") or die(mysql_error()) ; mysql_select_db("employees") or die(mysql_error()) ; //Retrieves data from MySQL $data = mysql_query("SELECT `img` FROM employees") or die(mysql_error()); //Puts it into an array while($info = mysql_fetch_array( $data )) { //Outputs the image and other data //Echo "<img src=http://www.yoursite.com/images/".$info['photo'] ."> <br>"; Echo "<img src=http://localhost/file_upload_new/images/".$info['photo'] ." width=\"200\" height=\"200\"> <br>"; mysql_close($dbconn); ?> in this code i can't use ['photo'] because in form photo name was not available. please understand what i m trying to say. i already paste the code of form(test.html). Quote Link to comment https://forums.phpfreaks.com/topic/260465-how-can-i-store-jpegcam-snapshots-in-mysql-using-php/#findComment-1335143 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.