<งานหลวงฟรี>อยากได้คำสั่ง php ที่สามรถ capture รูปจากกล้องแล้วเก็บ url ลงในดาต้า

เริ่มโดย builderinfos.com, 11 กุมภาพันธ์ 2013, 12:42:06

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

builderinfos.com

ขอรบกวนท่านที่เก่ง php หน่อยครับ

งานหลวง เพื่อคนแก่ ผู้ป่วยเบาหวาน ครับ จะทำกล้องถ่ายรูปฝ่าเท้าและเก็บรูปและประวัติคนไข้

***อยากได้คำสั่ง php ที่สามรถ capture รูปจากกล้องแล้วเก็บ url ลงในดาต้าเบส **

script กล้องผมมีแล้ว capture แล้วมันลง โฟนเด้อแล้ว แต่อยากให้มันเก็บ url images พร้อมกันตอน capture ลงใน database ด้วยครับ แล้วค่อยดึง url มาแสดง

คล้ายๆ facebook ที่สามารถ capture จาก webcam แล้วเก็บมาเป็น โปรไฟล์ ครับ


builderinfos.com

ตอน กด capture แล้วให้มันเก็บ url images ลงในดาต้าเบส พร้อมกันเลยครับ

ไม่ใช่เก็บรูปลง ดาต้าเบส นะครับ แค่ url images เท่านั้น แล้วค่อย ดึง url images นั้น มาแสดง อีกทีครับ

กำลังมึนมากครับ คือถ้าใช้คำสั่ง browse นั้นอะได้เลย แต่มันยุ่งยากต้องหารูปอีกเพราะ ชื่อรูป มัน random เลยมีความคิดว่า capture แล้วให้มันลงดาต้าเบส ไปเลย

zoomman

ผมว่าน่าจะเป็นการเก็บชื่อไฟล์ภาพ ลง database นะ
ที่ผมเคยทำคือใช้แฟลช ต่อกล้อง webcam (หรือกล้องคุณดีกว่าก็ได้)capture แล้วใช้  php script upload ขึ้น server
โดยชื่อไฟล์ภาพจะทำการ run เป็น yyyy-mm-dd-time() แค่นี้ก็สารพัดประโยชน์แล้วครับ
ลายเซ็น

builderinfos.com

ผมลงโค๊ดไว้ให้ช่วยดูนะคับ

โค๊ดกล้อง index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JPEGCam Test Page: Image Resize 2</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Joseph Huckaby">
<!-- Date: 2008-03-15 -->
</head>
<body>
<h1>JPEGCam Test Page with Different Preview and Submit Sizes</h1>
<h3>Demonstrates previewing video at 320x240, but submitting a 640x480 image to the server.</h3>

<!-- First, include the JPEGCam JavaScript Library -->
<script type="text/javascript" src="webcam.js"></script>

<!-- Configure a few settings -->
<script language="JavaScript">
webcam.set_api_url( 'test.php' );
webcam.set_quality( 90 ); // JPEG quality (1 - 100)
webcam.set_shutter_sound( true ); // play shutter click sound
</script>

<!-- Next, write the movie to the page at 320x240, but request the final image at 640x480 -->
<script language="JavaScript">
document.write( webcam.get_html(320, 240, 640, 480) );
</script>

<!-- Some buttons for controlling things -->
<br/><form>
<input type=button value="Configure..." onClick="webcam.configure()">
&nbsp;&nbsp;
<input type=button value="Take Snapshot" onClick="take_snapshot()">
</form>

<!-- Code to handle the server response (see test.php) -->
<script language="JavaScript">
webcam.set_hook( 'onComplete', 'my_completion_handler' );

function take_snapshot() {
// take snapshot and upload to server
document.getElementById('upload_results').innerHTML = '<h1>Uploading...</h1>';
webcam.snap();
}

function my_completion_handler(msg) {
// extract URL out of PHP output
if (msg.match(/(http://S )/)) {
var image_url = RegExp.$1;
// show JPEG image in page
document.getElementById('upload_results').innerHTML =
'<h1>Upload Successful!</h1>'   
'<h3>JPEG URL: '   image_url   '</h3>'   
'<img src="'   image_url   '">';

// reset camera for another shot
webcam.reset();
}
else alert("PHP Error: "   msg);
}
</script>

<br/><br/>
<div id="upload_results" style="background-color:#eee;"></div>
</body>
</html>


โค๊ด test.php

<?php

/* JPEGCam Test Script */
/* Receives JPEG webcam submission and saves to local file. */
/* Make sure your directory has permission to write files as your web server user! */

$filename date('YmdHis');
$images='images/'.$filename '.jpg';
$result file_put_contents$imagesfile_get_contents('php://input') );
if (!
$result) {
print "ERROR: Failed to write data to $filename, check permissions
"
;
exit();
}

$url 'http://' $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' $images;
print 
"$url
"
;

?>

builderinfos.com

อ้างถึงจาก: zoomman ใน 11 กุมภาพันธ์ 2013, 13:06:20
ผมว่าน่าจะเป็นการเก็บชื่อไฟล์ภาพ ลง database นะ
ที่ผมเคยทำคือใช้แฟลช ต่อกล้อง webcam (หรือกล้องคุณดีกว่าก็ได้)capture แล้วใช้  php script upload ขึ้น server
โดยชื่อไฟล์ภาพจะทำการ run เป็น yyyy-mm-dd-time() แค่นี้ก็สารพัดประโยชน์แล้วครับ

ใช่ครับ เก็บชื่อไฟล์ภาพ ลง database  ครับ ที่ ผมมึนมาก คืออยากให้มีปุ่มกด capture ทีเดียวแล้วให้มัน ลง database ไปเลย

gubaaball

อ้างถึงจาก: builderinfos.com ใน 11 กุมภาพันธ์ 2013, 13:07:09
ผมลงโค๊ดไว้ให้ช่วยดูนะคับ

โค๊ดกล้อง index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JPEGCam Test Page: Image Resize 2</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Joseph Huckaby">
<!-- Date: 2008-03-15 -->
</head>
<body>
<h1>JPEGCam Test Page with Different Preview and Submit Sizes</h1>
<h3>Demonstrates previewing video at 320x240, but submitting a 640x480 image to the server.</h3>

<!-- First, include the JPEGCam JavaScript Library -->
<script type="text/javascript" src="webcam.js"></script>

<!-- Configure a few settings -->
<script language="JavaScript">
webcam.set_api_url( 'test.php' );
webcam.set_quality( 90 ); // JPEG quality (1 - 100)
webcam.set_shutter_sound( true ); // play shutter click sound
</script>

<!-- Next, write the movie to the page at 320x240, but request the final image at 640x480 -->
<script language="JavaScript">
document.write( webcam.get_html(320, 240, 640, 480) );
</script>

<!-- Some buttons for controlling things -->
<br/><form>
<input type=button value="Configure..." onClick="webcam.configure()">
&nbsp;&nbsp;
<input type=button value="Take Snapshot" onClick="take_snapshot()">
</form>

<!-- Code to handle the server response (see test.php) -->
<script language="JavaScript">
webcam.set_hook( 'onComplete', 'my_completion_handler' );

function take_snapshot() {
// take snapshot and upload to server
document.getElementById('upload_results').innerHTML = '<h1>Uploading...</h1>';
webcam.snap();
}

function my_completion_handler(msg) {
// extract URL out of PHP output
if (msg.match(/(http://S )/)) {
var image_url = RegExp.$1;
// show JPEG image in page
document.getElementById('upload_results').innerHTML =
'<h1>Upload Successful!</h1>'   
'<h3>JPEG URL: '   image_url   '</h3>'   
'<img src="'   image_url   '">';

// reset camera for another shot
webcam.reset();
}
else alert("PHP Error: "   msg);
}
</script>

<br/><br/>
<div id="upload_results" style="background-color:#eee;"></div>
</body>
</html>


โค๊ด test.php

<?php

/* JPEGCam Test Script */
/* Receives JPEG webcam submission and saves to local file. */
/* Make sure your directory has permission to write files as your web server user! */

$filename date('YmdHis');
$images='images/'.$filename '.jpg';
$result file_put_contents$imagesfile_get_contents('php://input') );
if (!
$result) {
print "ERROR: Failed to write data to $filename, check permissions
"
;
exit();
}

$url 'http://' $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' $images;
print 
"$url
"
;

?>


ถ้าผมเข้าใจไม่ผิดน่ะครับ ก็เอาตัวแปร $url ไปเก็บในดาต้าเบสได้เลย เช่น สร้างตารางขึ้นมา picture ด้วยคำสั่ง sql นี้
CREATETABLE`picture` (
`pic_id` INT NOTNULLAUTO_INCREMENTPRIMARYKEY ,
`pic_url` VARCHAR( 200)NOTNULL
) ENGINE=MYISAM ;


แล้วก็ต่อจากบรรทัด $url ก็นำเข้าดาต้าเบสเมื่อกี้นี้ด้วยคำสั่ง

//ทำการ connect ดาต้าเบส แล้วใช้คำสั่ง insert

$sql="insert into picture(pic_url) values('$url')";
$res=mysql_query($sql);


เท่านี้ล่ะครับถ้าจะเก็บ url ลงในดาต้าเบส เวลาเรียกใช้ก็

//ทำการ connect ดาต้าเบส แล้วใช้คำสั่ง select

$sql="select * from picture;
$res=mysql_query($sql);

while($arr=mysql_fetch_assoc($res)){

echo '<img src="'.$arr['pic_url'].'" border="0" /><br /><br />';
}


** หากผิดพลาดประการใดก็ขออภัยด้วยครับ

goweb

ผมก็เข้าใจตามที่คุณ gubaaball บอกนะครับ

ตอนนี้ดูจากโค้ดแล้วมันดูอย่างเดียวครับยังไม่ได้เก็บลง folder หรือ databast ใดๆ

1. เอาชื่อไฟล์เก็บลงฐานข้อมูล
2. ทำการอัพโหลดรูปภาพที่อ่านได้ลง Folder ด้วยนะไม่งั้นมันจะไม่รู้ว่าไฟล์ภาพอยู่ที่ไหน

ลองดูโค้ดของคุณ gubaaball ได้เลยครับ
ถ้าทำอะไรดีแล้ว คนมองว่าสร้างภาพ ก็ช่างเขา
อย่างน้อยเราก็ได้ทำดี ไม่เหมือนเขาที่แค่คิดดี
ยังไม่ได้ทำเลย... พระมหาวุฒิชัย (ว.วชิรเมธี)
สาธุ..

xvlnw.com

ค่อนข้างยาก และต้องดัดแปลงอย่างมาก

คอนเสปของผมคือ
1. ถ่ายภาพไปเรื่อยๆเลยครับ การเรียงลำดับของรูปภาพ จะเรียงตามชื่อไฟล์อยู่แล้ว ถ่ายทีหลัง อยู่หลังสุด ถ่ายก่อนอยู่รูปแรกสุด
2. เอาคอนเสปการเรียงรูปมาใช้ครับ เขียน PHP อ่านไฟล์ในโฟเดอร์ เก็บชื่อลงฐานข้อมูล มันก็จะเรียงไปเรื่อยๆของมันเอง
2. ตอนเก็บ ก็เชคก่อนว่ารูปมีอยู่ในฐานข้อมูลหรือยัง ถ้ายังก็คัดลอกรูปไปไว้อีกโฟเดอร์ แสดงว่าเก็บแล้ว แล้วก็ลบรูปในเมมกล้องซะ หรือจะใช้วิธีการย้ายรูปไปเลยในขึ้นตอนเดียว ระหว่างนั้นก็เก็บชื่อรูปลง DB ได้แล้วครับ

การทำงานนี้ ก็หมายถึงการให้ PHP ทำงานให้แบบ Auto ง่ายๆครับ สั่งให้ Refresh หน้าจอเว็บบราวเซอร์ทุกๆ 60 วินาที หรือเท่าไรก็ว่าไป มันก็จะทำงานของมันเองไปเรื่อยๆ ที่สำคัญคือการตั้งค่า Path ของรูปให้ถูกต้องครับ

ส่วนโค๊ดอื่นๆ ไม่มีนะครับ ให้หลักการไปลองเขียนโค๊ดเอาครับ
:wanwan003:
[direct=https://cloudhost.in.th/wordpress-hosting]ツ ⓌⓄⓇⒹⓅⓇⒺⓈⓈ ⒽⓄⓈⓉⒾⓃⒼ [/direct] :wanwan014:  :D
[direct=https://cloudhost.in.th/cloudhosting.html]Cloud Hosting[/direct] [direct=https://cloudhost.in.th/cloudvps.html]Cloud Server[/direct] [direct=https://cloudhost.in.th/vpshosting.html]Cloud VPS Hosting[/direct] [direct=https://cloudhost.in.th/windowsvps.html]Cloud Windows[/direct] Tel: 080-348-0843 LINE: ixvlnw

allofnone

ได้ความรู้เลยครับ

ยังไม่เคยมีประสบการณ์เขียน php ต่อกับฮาร์ดแวร์มาก่อนเลย

builderinfos.com

อ้างถึงจาก: gubaaball ใน 11 กุมภาพันธ์ 2013, 13:18:20
อ้างถึงจาก: builderinfos.com ใน 11 กุมภาพันธ์ 2013, 13:07:09
ผมลงโค๊ดไว้ให้ช่วยดูนะคับ

โค๊ดกล้อง index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JPEGCam Test Page: Image Resize 2</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Joseph Huckaby">
<!-- Date: 2008-03-15 -->
</head>
<body>
<h1>JPEGCam Test Page with Different Preview and Submit Sizes</h1>
<h3>Demonstrates previewing video at 320x240, but submitting a 640x480 image to the server.</h3>

<!-- First, include the JPEGCam JavaScript Library -->
<script type="text/javascript" src="webcam.js"></script>

<!-- Configure a few settings -->
<script language="JavaScript">
webcam.set_api_url( 'test.php' );
webcam.set_quality( 90 ); // JPEG quality (1 - 100)
webcam.set_shutter_sound( true ); // play shutter click sound
</script>

<!-- Next, write the movie to the page at 320x240, but request the final image at 640x480 -->
<script language="JavaScript">
document.write( webcam.get_html(320, 240, 640, 480) );
</script>

<!-- Some buttons for controlling things -->
<br/><form>
<input type=button value="Configure..." onClick="webcam.configure()">
&nbsp;&nbsp;
<input type=button value="Take Snapshot" onClick="take_snapshot()">
</form>

<!-- Code to handle the server response (see test.php) -->
<script language="JavaScript">
webcam.set_hook( 'onComplete', 'my_completion_handler' );

function take_snapshot() {
// take snapshot and upload to server
document.getElementById('upload_results').innerHTML = '<h1>Uploading...</h1>';
webcam.snap();
}

function my_completion_handler(msg) {
// extract URL out of PHP output
if (msg.match(/(http://S )/)) {
var image_url = RegExp.$1;
// show JPEG image in page
document.getElementById('upload_results').innerHTML =
'<h1>Upload Successful!</h1>'   
'<h3>JPEG URL: '   image_url   '</h3>'   
'<img src="'   image_url   '">';

// reset camera for another shot
webcam.reset();
}
else alert("PHP Error: "   msg);
}
</script>

<br/><br/>
<div id="upload_results" style="background-color:#eee;"></div>
</body>
</html>


โค๊ด test.php

<?php

/* JPEGCam Test Script */
/* Receives JPEG webcam submission and saves to local file. */
/* Make sure your directory has permission to write files as your web server user! */

$filename date('YmdHis');
$images='images/'.$filename '.jpg';
$result file_put_contents$imagesfile_get_contents('php://input') );
if (!
$result) {
print "ERROR: Failed to write data to $filename, check permissions
"
;
exit();
}

$url 'http://' $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' $images;
print 
"$url
"
;

?>


ถ้าผมเข้าใจไม่ผิดน่ะครับ ก็เอาตัวแปร $url ไปเก็บในดาต้าเบสได้เลย เช่น สร้างตารางขึ้นมา picture ด้วยคำสั่ง sql นี้
CREATETABLE`picture` (
`pic_id` INT NOTNULLAUTO_INCREMENTPRIMARYKEY ,
`pic_url` VARCHAR( 200)NOTNULL
) ENGINE=MYISAM ;


แล้วก็ต่อจากบรรทัด $url ก็นำเข้าดาต้าเบสเมื่อกี้นี้ด้วยคำสั่ง

//ทำการ connect ดาต้าเบส แล้วใช้คำสั่ง insert

$sql="insert into picture(pic_url) values('$url')";
$res=mysql_query($sql);


เท่านี้ล่ะครับถ้าจะเก็บ url ลงในดาต้าเบส เวลาเรียกใช้ก็

//ทำการ connect ดาต้าเบส แล้วใช้คำสั่ง select

$sql="select * from picture;
$res=mysql_query($sql);

while($arr=mysql_fetch_assoc($res)){

echo '<img src="'.$arr['pic_url'].'" border="0" /><br /><br />';
}


** หากผิดพลาดประการใดก็ขออภัยด้วยครับ

ขอบคุณครับทดลองแล้ว ยังไม่ได้เหมือนเดิมครับผ๊ม


pulimz

อ้างถึงจาก: builderinfos.com ใน 11 กุมภาพันธ์ 2013, 22:49:11
อ้างถึงจาก: gubaaball ใน 11 กุมภาพันธ์ 2013, 13:18:20
อ้างถึงจาก: builderinfos.com ใน 11 กุมภาพันธ์ 2013, 13:07:09
ผมลงโค๊ดไว้ให้ช่วยดูนะคับ

โค๊ดกล้อง index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JPEGCam Test Page: Image Resize 2</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Joseph Huckaby">
<!-- Date: 2008-03-15 -->
</head>
<body>
<h1>JPEGCam Test Page with Different Preview and Submit Sizes</h1>
<h3>Demonstrates previewing video at 320x240, but submitting a 640x480 image to the server.</h3>

<!-- First, include the JPEGCam JavaScript Library -->
<script type="text/javascript" src="webcam.js"></script>

<!-- Configure a few settings -->
<script language="JavaScript">
webcam.set_api_url( 'test.php' );
webcam.set_quality( 90 ); // JPEG quality (1 - 100)
webcam.set_shutter_sound( true ); // play shutter click sound
</script>

<!-- Next, write the movie to the page at 320x240, but request the final image at 640x480 -->
<script language="JavaScript">
document.write( webcam.get_html(320, 240, 640, 480) );
</script>

<!-- Some buttons for controlling things -->
<br/><form>
<input type=button value="Configure..." onClick="webcam.configure()">
&nbsp;&nbsp;
<input type=button value="Take Snapshot" onClick="take_snapshot()">
</form>

<!-- Code to handle the server response (see test.php) -->
<script language="JavaScript">
webcam.set_hook( 'onComplete', 'my_completion_handler' );

function take_snapshot() {
// take snapshot and upload to server
document.getElementById('upload_results').innerHTML = '<h1>Uploading...</h1>';
webcam.snap();
}

function my_completion_handler(msg) {
// extract URL out of PHP output
if (msg.match(/(http://S )/)) {
var image_url = RegExp.$1;
// show JPEG image in page
document.getElementById('upload_results').innerHTML =
'<h1>Upload Successful!</h1>'   
'<h3>JPEG URL: '   image_url   '</h3>'   
'<img src="'   image_url   '">';

// reset camera for another shot
webcam.reset();
}
else alert("PHP Error: "   msg);
}
</script>

<br/><br/>
<div id="upload_results" style="background-color:#eee;"></div>
</body>
</html>


โค๊ด test.php

<?php

/* JPEGCam Test Script */
/* Receives JPEG webcam submission and saves to local file. */
/* Make sure your directory has permission to write files as your web server user! */

$filename date('YmdHis');
$images='images/'.$filename '.jpg';
$result file_put_contents$imagesfile_get_contents('php://input') );
if (!
$result) {
print "ERROR: Failed to write data to $filename, check permissions
"
;
exit();
}

$url 'http://' $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' $images;
print 
"$url
"
;

?>


ถ้าผมเข้าใจไม่ผิดน่ะครับ ก็เอาตัวแปร $url ไปเก็บในดาต้าเบสได้เลย เช่น สร้างตารางขึ้นมา picture ด้วยคำสั่ง sql นี้
CREATETABLE`picture` (
`pic_id` INT NOTNULLAUTO_INCREMENTPRIMARYKEY ,
`pic_url` VARCHAR( 200)NOTNULL
) ENGINE=MYISAM ;


แล้วก็ต่อจากบรรทัด $url ก็นำเข้าดาต้าเบสเมื่อกี้นี้ด้วยคำสั่ง

//ทำการ connect ดาต้าเบส แล้วใช้คำสั่ง insert

$sql="insert into picture(pic_url) values('$url')";
$res=mysql_query($sql);


เท่านี้ล่ะครับถ้าจะเก็บ url ลงในดาต้าเบส เวลาเรียกใช้ก็

//ทำการ connect ดาต้าเบส แล้วใช้คำสั่ง select

$sql="select * from picture;
$res=mysql_query($sql);

while($arr=mysql_fetch_assoc($res)){

echo '<img src="'.$arr['pic_url'].'" border="0" /><br /><br />';
}


** หากผิดพลาดประการใดก็ขออภัยด้วยครับ

ขอบคุณครับทดลองแล้ว ยังไม่ได้เหมือนเดิมครับผ๊ม

ลองเปลี่ยนเป็นเก็บ $filename แทนครับ ลงฐานข้อมูล  .jpg ให้มันด้วยเลยก็ได้
คิวรี จากฐานข้อมูลออกมาแสดงให้ตรง path

ผิดพลาดก็ขออภัยด้วยครับ