prosperchild Posted January 29, 2023 Share Posted January 29, 2023 The HTML code is a registration form with input fields for registration number and password and a video element to capture the user's photo. The JavaScript code uses the getUserMedia API to access the user's camera and display the video stream in the video element. When the upload button is clicked, the video frame is drawn to a canvas, the image data is retrieved from the canvas and added to a FormData object along with the registration number and password. The registration button has a retake and upload file button displaying when the regno of the user is found in the mysql database, using php pdo. The FormData object is then sent to the server via an XMLHttpRequest to the "upload_image.php" file for processing. The first PHP file "upload_image.php" connects to a MySQL database using PDO, retrieves the image data and registration number from the POST request, checks if the registration number exists in the database, if it does, it updates the image data in the table, if the registration number does not exist in the database, it returns an error message. The second PHP file "verify_user.php" is called via a fetch call to verify the user by checking registration number and password, if the user is verified, it will show the video container and allow user to take a photo. Here is my scripts: front-end page:members.php NOTE: Script code removed, see script below. The script isnt working..No image uploaded to database? i want the image stored in mysql database to be in varchar and not in blob form? How do i achieve this task? is there a better ways? Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/ Share on other sites More sharing options...
requinix Posted January 29, 2023 Share Posted January 29, 2023 That code sure looks unreadable in that shape, don't you think? Try replying with your code again, but use the Code <> button this time. Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/#findComment-1605161 Share on other sites More sharing options...
prosperchild Posted January 29, 2023 Author Share Posted January 29, 2023 (edited) The HTML code is a registration form with input fields for registration number and password and a video element to capture the user's photo. The JavaScript code uses the getUserMedia API to access the user's camera and display the video stream in the video element. When the upload button is clicked, the video frame is drawn to a canvas, the image data is retrieved from the canvas and added to a FormData object along with the registration number and password. The registration button has a retake and upload file button displaying when the regno of the user is found in the mysql database, using php pdo. The FormData object is then sent to the server via an XMLHttpRequest to the "upload_image.php" file for processing. The first PHP file "upload_image.php" connects to a MySQL database using PDO, retrieves the image data and registration number from the POST request, checks if the registration number exists in the database, if it does, it updates the image data in the table, if the registration number does not exist in the database, it returns an error message. The second PHP file "verify_user.php" is called via a fetch call to verify the user by checking registration number and password, if the user is verified, it will show the video container and allow user to take a photo. Here is my scripts: front-end page:members.php <html> <head> <title>Registration Form</title> </head> <body> <form id="registration-form" enctype="multipart/form-data"> <div> <label for="regno">Registration Number:</label> <input type="text" id="regno"> </div> <div> <label for="password">Password:</label> <input type="password" id="password"> </div> <div> <video id="video" width="400" height="300"></video> </div> <div> <button type="button" id="verify">Verify</button> <button type="button" id="upload">Upload Image</button> <button type="button" id="retake">Retake</button> <button type="button" id="uploadFile">Upload File</button> </div> </form> <script> // Get user media and display video stream let video = document.querySelector('video'); navigator.mediaDevices.getUserMedia({ video: true }) .then(stream => { video.srcObject = stream; video.play(); }); // Capture image from video stream let uploadButton = document.querySelector('#upload'); uploadButton.addEventListener('click', e => { let canvas = document.createElement('canvas'); let context = canvas.getContext('2d'); canvas.width = video.videoWidth; canvas.height = video.videoHeight; context.drawImage(video, 0, 0, canvas.width, canvas.height); let imageData = canvas.toDataURL('image/jpeg'); // Encrypt the parameters let encryptedParams = CryptoJS.AES.encrypt(JSON.stringify({ imageData: imageData, regno: document.querySelector('#regno').value, password: document.querySelector('#password').value }), 'secret key'); // Send encrypted parameters to server let xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = () => { if (xhttp.readyState == 4 && xhttp.status == 200) { let response = JSON.parse(xhttp.response); if (response.status == 'success') { document.querySelector('#retake').style.display = 'none'; document.querySelector('#uploadFile').style.display = 'none'; } else { alert('Error: ' + response.message); } } }; xhttp.open("POST", "upload_image.php", true); xhttp.send(encryptedParams); }); // Verify_use.php let verifyButton = document.querySelector('#verify'); verifyButton.addEventListener('click', e => { let regno = document.querySelector('#regno').value; let password = document.querySelector('#password').value; // Encrypt the parameters let encryptedParams = CryptoJS.AES.encrypt(JSON.stringify({ regno: regno, password: password }), 'secret key'); // Send encrypted parameters to server let xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = () => { if (xhttp.readyState == 4 && xhttp.status == 200) { let response = JSON.parse(xhttp.response); if (response.status == 'success') { document.querySelector('#videoContainer').style.display = 'block'; } else { alert('Error: ' + response.message); } } }; xhttp.open("POST", "verify_user.php", true); xhttp.send(encryptedParams); }); </script> </body> </html> upload_image.php script: <?php // upload_image.php // Connect to MySQL database $host = 'localhost'; $dbname = 'school'; $username = 'root'; $password = ''; try { $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Retrieve image data from POST request $imageData = $_POST['imageData']; $regno = $_POST['regno']; // Check if registration number exists in database $stmt = $conn->prepare('SELECT * FROM users WHERE regno = :regno'); $stmt->execute(['regno' => $regno]); $result = $stmt->fetch(); // If registration number exists, update image data if ($result) { $stmt = $conn->prepare('UPDATE users SET image = :imageData WHERE regno = :regno'); $stmt->execute(['imageData' => $imageData, 'regno' => $regno]); // Return success response echo json_encode(['status' => 'success']); } else { // Return error response echo json_encode(['status' => 'error', 'message' => 'Registration number does not exist in database']); } } catch(PDOException $e) { echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); } ?> verify_user.php: <?php // verify_user.php // Connect to MySQL database $host = 'localhost'; $dbname = 'school'; $username = 'root'; $password = ''; try { $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Retrieve registration number and password from GET request $regno = $_GET['regno']; $password = $_GET['password']; // Check if registration number and password match in database $stmt = $conn->prepare('SELECT image FROM users WHERE regno = :regno'); $stmt->execute(['regno' => $regno]); $imageData = $stmt->fetchColumn(); // Convert image data to varchar $imageString = base64_encode($imageData); // Update image data in database $stmt = $conn->prepare('UPDATE users SET image = :imageString WHERE regno = :regno'); $stmt->execute(['imageString' => $imageString, 'regno' => $regno]); // Check if update was successful if ($stmt->rowCount() > 0) { echo 'Image data successfully updated to varchar in database.'; } else { echo 'Error: Image data could not be updated to varchar in database.'; } // Close database connection $conn = null; } catch(PDOException $e) { echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); } ?> Edited January 29, 2023 by prosperchild Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/#findComment-1605162 Share on other sites More sharing options...
prosperchild Posted January 29, 2023 Author Share Posted January 29, 2023 On 1/28/2023 at 11:38 PM, prosperchild said: <html> <head> <title>Registration Form</title> </head> <body> <form id="registration-form" enctype="multipart/form-data"> <div> <label for="regno">Registration Number:</label> <input type="text" id="regno"> </div> <div> <label for="password">Password:</label> <input type="password" id="password"> </div> <div> <video id="video" width="400" height="300"></video> </div> <div> <button type="button" id="verify">Verify</button> <button type="button" id="upload">Upload Image</button> <button type="button" id="retake">Retake</button> <button type="button" id="uploadFile">Upload File</button> </div> </form> <script> // Get user media and display video stream let video = document.querySelector('video'); navigator.mediaDevices.getUserMedia({ video: true }) .then(stream => { video.srcObject = stream; video.play(); }); // Capture image from video stream let uploadButton = document.querySelector('#upload'); uploadButton.addEventListener('click', e => { let canvas = document.createElement('canvas'); let context = canvas.getContext('2d'); canvas.width = video.videoWidth; canvas.height = video.videoHeight; context.drawImage(video, 0, 0, canvas.width, canvas.height); let imageData = canvas.toDataURL('image/jpeg'); // Encrypt the parameters let encryptedParams = CryptoJS.AES.encrypt(JSON.stringify({ imageData: imageData, regno: document.querySelector('#regno').value, password: document.querySelector('#password').value }), 'secret key'); // Send encrypted parameters to server let xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = () => { if (xhttp.readyState == 4 && xhttp.status == 200) { let response = JSON.parse(xhttp.response); if (response.status == 'success') { document.querySelector('#retake').style.display = 'none'; document.querySelector('#uploadFile').style.display = 'none'; } else { alert('Error: ' + response.message); } } }; xhttp.open("POST", "upload_image.php", true); xhttp.send(encryptedParams); }); // Verify_use.php let verifyButton = document.querySelector('#verify'); verifyButton.addEventListener('click', e => { let regno = document.querySelector('#regno').value; let password = document.querySelector('#password').value; // Encrypt the parameters let encryptedParams = CryptoJS.AES.encrypt(JSON.stringify({ regno: regno, password: password }), 'secret key'); // Send encrypted parameters to server let xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = () => { if (xhttp.readyState == 4 && xhttp.status == 200) { let response = JSON.parse(xhttp.response); if (response.status == 'success') { document.querySelector('#videoContainer').style.display = 'block'; } else { alert('Error: ' + response.message); } } }; xhttp.open("POST", "verify_user.php", true); xhttp.send(encryptedParams); }); </script> </body> </html> upload_image.php script: <?php // upload_image.php // Connect to MySQL database $host = 'localhost'; $dbname = 'school'; $username = 'root'; $password = ''; try { $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Retrieve image data from POST request $imageData = $_POST['imageData']; $regno = $_POST['regno']; // Check if registration number exists in database $stmt = $conn->prepare('SELECT * FROM users WHERE regno = :regno'); $stmt->execute(['regno' => $regno]); $result = $stmt->fetch(); // If registration number exists, update image data if ($result) { $stmt = $conn->prepare('UPDATE users SET image = :imageData WHERE regno = :regno'); $stmt->execute(['imageData' => $imageData, 'regno' => $regno]); // Return success response echo json_encode(['status' => 'success']); } else { // Return error response echo json_encode(['status' => 'error', 'message' => 'Registration number does not exist in database']); } } catch(PDOException $e) { echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); } ?> verify_user.php: <?php // verify_user.php // Connect to MySQL database $host = 'localhost'; $dbname = 'school'; $username = 'root'; $password = ''; try { $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Retrieve registration number and password from GET request $regno = $_GET['regno']; $password = $_GET['password']; // Check if registration number and password match in database $stmt = $conn->prepare('SELECT image FROM users WHERE regno = :regno'); $stmt->execute(['regno' => $regno]); $imageData = $stmt->fetchColumn(); // Convert image data to varchar $imageString = base64_encode($imageData); // Update image data in database $stmt = $conn->prepare('UPDATE users SET image = :imageString WHERE regno = :regno'); $stmt->execute(['imageString' => $imageString, 'regno' => $regno]); // Check if update was successful if ($stmt->rowCount() > 0) { echo 'Image data successfully updated to varchar in database.'; } else { echo 'Error: Image data could not be updated to varchar in database.'; } // Close database connection $conn = null; } catch(PDOException $e) { echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); } ?> The HTML code is a registration form with input fields for registration number and password and a video element to capture the user's photo. The JavaScript code uses the getUserMedia API to access the user's camera and display the video stream in the video element. When the upload button is clicked, the video frame is drawn to a canvas, the image data is retrieved from the canvas and added to a FormData object along with the registration number and password. The registration button has a retake and upload file button displaying when the regno of the user is found in the mysql database, using php pdo. The FormData object is then sent to the server via an XMLHttpRequest to the "upload_image.php" file for processing. The first PHP file "upload_image.php" connects to a MySQL database using PDO, retrieves the image data and registration number from the POST request, checks if the registration number exists in the database, if it does, it updates the image data in the table, if the registration number does not exist in the database, it returns an error message. The second PHP file "verify_user.php" is called via a fetch call to verify the user by checking registration number and password, if the user is verified, it will show the video container and allow user to take a photo. Here is my scripts: front-end page:members.php Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/#findComment-1605166 Share on other sites More sharing options...
prosperchild Posted January 29, 2023 Author Share Posted January 29, 2023 The HTML code is a registration form with input fields for registration number and password and a video element to capture the user's photo. The JavaScript code uses the getUserMedia API to access the user's camera and display the video stream in the video element. When the upload button is clicked, the video frame is drawn to a canvas, the image data is retrieved from the canvas and added to a FormData object along with the registration number and password. The registration button has a retake and upload file button displaying when the regno of the user is found in the mysql database, using php pdo. The FormData object is then sent to the server via an XMLHttpRequest to the "upload_image.php" file for processing. The first PHP file "upload_image.php" connects to a MySQL database using PDO, retrieves the image data and registration number from the POST request, checks if the registration number exists in the database, if it does, it updates the image data in the table, if the registration number does not exist in the database, it returns an error message. The second PHP file "verify_user.php" is called via a fetch call to verify the user by checking registration number and password, if the user is verified, it will show the video container and allow user to take a photo. Here is my scripts: front-end page:members.php. Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/#findComment-1605169 Share on other sites More sharing options...
ginerjm Posted January 30, 2023 Share Posted January 30, 2023 Does your editor not recognize carriage returns? Reading your posts is a PIA. Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/#findComment-1605187 Share on other sites More sharing options...
Barand Posted January 30, 2023 Share Posted January 30, 2023 The problem is his posting the text parts of the posts in the code boxes so that no line wrapping occurs. And yes, a PIA. (I usually skip posts that require me to scroll right into the middle of next week in order to read them.) Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/#findComment-1605191 Share on other sites More sharing options...
ginerjm Posted January 30, 2023 Share Posted January 30, 2023 After seeing ALL of these posts that were impossible to read I felt like giving the OP a 'suggestion' perhaps. OP - if the post is not easily readable by you when you create it, why would you want to post it for US to try and read something like that? We would like to help you out but not if it means we have to struggle to understand it. Make It Easy for us please. Code with basically one instruction per line, text that one doesn't have to scroll through left and right. Code that is in text format and not an image file or something which we cannot copy into our editor and modify to show you what we are suggesting. Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/#findComment-1605193 Share on other sites More sharing options...
gizmola Posted January 31, 2023 Share Posted January 31, 2023 I went through and tried to clean up/make sense of the OP's posts, and lack of experience with the forum tools. To @prosperchild Start with your description text etc. in the editor window Don't write up everything in another editor and try and paste it all into a code snippet When it is time to put a snippet into the post Use the code snippet button: <> Paste the code snippet into that window, set language appropriately to reflect the language DO: use one or more snippets for each file you are trying to get help with DON'T: paste the code from a bunch of different source files/multiple languages into one snippet. Use different code Snippets for each portion of the code Example: "Hey, this code has a bug, around line xyz that says: blah blah blah. I am not sure how to fix this" /Index.html Use <> Code snippet button here <html> <header> </header> <body> </body> </html> sources/code.php Use <> Code snippet button again here <?php phpinfo(); die('What is going on?'); 1 Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/#findComment-1605217 Share on other sites More sharing options...
gizmola Posted January 31, 2023 Share Posted January 31, 2023 On 1/28/2023 at 10:55 PM, prosperchild said: The HTML code is a registration form with input fields for registration number and password and a video element to capture the user's photo. The JavaScript code uses the getUserMedia API to access the user's camera and display the video stream in the video element. When the upload button is clicked, the video frame is drawn to a canvas, the image data is retrieved from the canvas and added to a FormData object along with the registration number and password. The registration button has a retake and upload file button displaying when the regno of the user is found in the mysql database, using php pdo. The FormData object is then sent to the server via an XMLHttpRequest to the "upload_image.php" file for processing. The first PHP file "upload_image.php" connects to a MySQL database using PDO, retrieves the image data and registration number from the POST request, checks if the registration number exists in the database, if it does, it updates the image data in the table, if the registration number does not exist in the database, it returns an error message. The second PHP file "verify_user.php" is called via a fetch call to verify the user by checking registration number and password, if the user is verified, it will show the video container and allow user to take a photo. Here is my scripts: front-end page:members.php NOTE: Script code removed, see script below. The script isnt working..No image uploaded to database? i want the image stored in mysql database to be in varchar and not in blob form? How do i achieve this task? is there a better ways? I have not looked through all the code, but to begin with, no you can not store image data (binary data) in a varchar field. FIrst of all, varchar fields have a fixed maximum length (64k), but they also are limited to characters and a character set. The data for an image is a byte stream of values, so you must use a blob field to store raw image data. There is a way to "encode" binary data in a format that transforms it into a text version, and in fact this format (base64) is built into browsers, such that it is possible to include in an html page an "inline image", and this format is base64. Here is an example of that (which is the mysql logo as a jpg image): <img src=" data:image/jpeg; data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQ gFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQM EBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB QUFBQUFBQUFBT/wAARCAAuADUDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAw QFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS 0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXq DhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6er x8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBA cFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygp KjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoq OkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMB AAIRAxEAPwD9EKKKKACq+oXyadZy3Eiu6xjO2NdzHnAA/HueB1JAqxTZI1mjZHUOjDaysMgg9QafqIzrH xHY30yweabe6LFPs1ypik3AZIAP3uOcrkEcgkc1p1i2ul2+p6XNYX0f2uKNjBlySGCn5WHOQwBHzDB3DO eBTPD9xcWd5daNeztdS26rLb3Eh+eWBiQN3q6kFSe42seWIFuK1sQpPS5u0UUVmaBRXj/wn+Iuoroesz eKtQF20enx+I7eXaoK2MqufLwoGSjRODx/EtHgf4haz4d0fxBJ4zklvLmz1q2tpTCqAWaXSQMgPTKRtMA TyeCea6Xh5ptdjkjiYNRff8PU9gorlNf8YTx3Wv6RpFnNc6xp+mJfK2wNGWkMiogGclv3THGOmPWq+l67 a6f4Z1PW7fXLrXYreB5XhuTGCkigkqQqBkPbaeB6V4mIx1PDV/Y1F9nmb02187vbWydtL7o9mhhJ4il7W D+1y213/JeV99exsxaPfQ+IPti33/EvSN0WyUYDtI4Z3f1ZSo246BnBzkEL4ksU8uPVBdS2U+nK8omijMuY 8ZdGQDLqdoOBzlVxzXN6o2t+HfDqeIpdYmu7qERz3diyILZ4yRvRBt3KQCdrZJJAznNbmh6jc3XirxFbyTNJ bW/2byIyBhN0ZLY78n1rGlm0Z1oUZ03GUrWTts4zkno3/JJNb38tTSplrjSlUhNSir9904prVL+ZNdLeZo6H qbatp6XLRGNW+4/G2VcAiReSQpB6HkfqSrNpY29grrbQpAjuZGWNdoLHknA7k8n1NFey7X0PMV7ank M/wh1e40b4eWyvDC1jZJpWuxswbzrPEbvGDj5vnhVOO0jH1zqa54Nj874nya/c2un6Br9tAkV3NMq7Ct syOxzjbtIUj6Zr1Gq19ptnqiRpeWsF2kciyos8YcI46MMjgjsa6Pbyb1/rW5y/V4Jaf1pY8/8AhDb6xdeGb3x XqVkkev6+Ibj7LK5jCRRxLHErHBK7gGkxjIMpBHFX5vCd34m1e/u7ywi0SK506awl8uVZZbgvtw77RjCYO OSfm7V3VFeRjsHTzCadZvlX2dLeWtub7mvPqerg8TPAwapL3v5tb+fW33p+XQ891qPxBeeGYtI1PSc248 qK+vLGXzjJEpBYxxYDEsFxjGV3cbsVqx2usaT4t1a6t9MS9s79rfEouVjMYRArHaRz1J/CutorzllCU1U9tLm VrP3brlUlb4bNWm91e7vc73mTcHD2UbO9171ndxd973vFdbeQyNnZnDoFAPBBzkUU+iveSsrXPHep/9 k= " alt="MySQL" /> So, it would be technically possible to base64 encode the raw image data, and store it in a text type field, then either include it in an inline tag or decode it from base64 after it's fetched and return that data. I'm not going to go into the many issues and reasons that for most people this would be a bad idea, but since you asked, I presented the technical background. I don't know what your reasoning is behind wanting to try and store image data in your database as something other than as a blob. I would suggest you explain your reasoning, and the desire to make this type of change, so people can provide you some usable feedback and suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/#findComment-1605221 Share on other sites More sharing options...
prosperchild Posted February 1, 2023 Author Share Posted February 1, 2023 (edited) On 1/29/2023 at 9:00 AM, prosperchild said: pros and cons of having it in the DB: pros: - all data in one place - easy to have for local use cons: - takes up a lot of space - DB is more likely to have finite space - have to use more compute power on your application server to retrieve image pros and cons of sotring just the URL in the DB: pros: - much smallers - more portable - more readable - easily expand storage on cloud hosts I prefer store it as path in the database than blob type which we make my database grow necessarily M On 1/29/2023 at 12:21 PM, prosperchild said: On 1/29/2023 at 9:00 AM, prosperchild said: This is the updated code Edited February 1, 2023 by prosperchild Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/#findComment-1605238 Share on other sites More sharing options...
ginerjm Posted February 1, 2023 Share Posted February 1, 2023 I totally agree. Storing image files and such as columns in a table is just not right. Better, as you said, to store the name of that file and have a pre-set path that your app uses to find it. Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/#findComment-1605251 Share on other sites More sharing options...
gizmola Posted February 5, 2023 Share Posted February 5, 2023 Yes, storing a path is the way to go, but you also need good reliable routines for maintaining the images. Typically, you need a table that stores: the "stored" filename When you move the uploaded file, you should change the name to something you use internally via a sha1 hash. this insures that you won't have name collisions from users uploading a file with the same name it protects you against named based exploits The original name when the image was submitted You can use this if you allow users to download the file as the original name it was uploaded as The mimetype (not strictly required, but a best practice in many cases) The path to the image file Quote Link to comment https://forums.phpfreaks.com/topic/315848-how-to-use-a-web-browser-to-take%C2%A0-camera-send-the-captured-image-to-mysql-database-with-validation/#findComment-1605402 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.