Jump to content

how can i store jpegcam snapshots in mysql using php


saran_singh

Recommended Posts

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.