How can I save an image from a file input field using PHP & MySQL?

How can I save an image from a file input field using PHP & MySQL?

Content Index :

How can I save an image from a file input field using PHP & MySQL?
Tag : php , By : goffi
Date : January 10 2021, 01:49 PM

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Save file from Database image field

Tag : chash , By : Justin Bowers
Date : March 29 2020, 07:55 AM
like below fixes the issue It sounds like you've got too much of the rest of the page going to the client. You need to clear the response, and close it afterwards; try:
sender.Response.ContentType = uf.FileType; // the binary data
sender.Response.AddHeader("Content-Disposition", "attachment; filename="
         + uf.FileName);

How to save the name of the image from an input file

Tag : php , By : Alpinfish
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further There are a few ways of doing this, but the easiest to understand is to have an input field that is not part of the schema of your table. For example, instead of image_cover you could have image_file:
 echo $this->Form->file('image_file');

Replace certain field from file with user input for each row and save in same file

Tag : linux , By : Jody Bannon
Date : March 29 2020, 07:55 AM
hop of those help? Answer to first question
If you only need to replace 1992 with 1994 and 1993 with 1995, you don't need a script, you can do it easily using sed:
sed "s/;1992/;1994/g" test.csv | sed "s/;1993/;1995/g" 
[shell] ➤ sed "s/;1992/;1994/g" test.csv | sed "s/;1993/;1995/g"
sed "s/;1992/;1994/g" test.csv | sed "s/;1993/;1995/g" > temp; mv temp test.scv 

if [ -z "${1}" ];then
        echo "Usage: $0 <filename>"
        sed "s/;1992/;1994/g" $FILENAME| sed "s/;1993/;1995/g"
[shell] ➤ ./test3.sh
Usage: ./test3.sh <filename>

[shell] ➤ ./test3.sh test.csv
if [ -z "${3}" ];then
        echo "Usage: <filename> <delimiter> <field_no>"
        FILENAME=$(readlink -f $1)
        if [ -f $TEMP_FILE ]; then
            rm $TEMP_FILE
        for line in $(cat $FILENAME)
                oldValue=`echo $line|cut -d$DELIMITER -f$FIELD_NO`
                echo "Enter the value to replace [$oldValue]"
                read newValue
                echo $line | sed "s/${oldValue}/${newValue}/g" >> $TEMP_FILE

How can I convert an image to base64 using input field when user clicks save

Tag : javascript , By : Adil
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You can't directly convert an image into base64 encoding using javascript, but you can paint the image onto a 2-dimensional HTML5 canvas and then convert the canvas-painted image into base64 encoding using javascript.
You can approach this in 3 steps:
var body = document.getElementsByTagName('body')[0];

function convertImage() {
    this.crossOrigin = 'Anonymous';
    var canvas = document.createElement('canvas');
    canvas.width = this.width;
    canvas.height = this.height;
    var canvasContext = canvas.getContext('2d');
    canvasContext.drawImage(this, 0, 0);

    var base64URL = canvas.toDataURL();
    var paragraph = document.createElement('p');
    paragraph.textContent = base64URL;

function loadImage() {
    var image = document.createElement('img');
    image.setAttribute('alt','Placeholder Image');

img, canvas, p {
display: inline-block;
margin-right: 12px;
width: 140px;
height: 200px;

p {
font-size: 9px;
overflow: scroll;

Display image on keyboard input and save input to file

Tag : javascript , By : agjimenez
Date : March 29 2020, 07:55 AM
I wish this help you Here you go. I've included comments explaining what was done along the way.
As I was saying, you need to actually do something with the data you retrieve from your server.
  //This truncates the document when the page is refreshed.
  fopen("saved_chars.txt", "w+");

  //Get the images in the same folder as this script
  $dir = getcwd()."/";
  $fileType = ".png";
  $width = "663";
  $height = "733";
  $folder = basename($dir);
  $filelist = glob("$dir*$fileType", GLOB_NOESCAPE);

  //Because glob() returns absolute filepaths on the server, we need
  //to replace the current directory with an empty string, so we
  //are left with the image filepaths, relative to the webpage's location.
  $n_filelist = array();
  foreach($filelist as $filename){
    $filename = str_replace($dir,"",$filename);
  $filelist = $n_filelist;
<!DOCTYPE html>
  <h2>Capture Response from Keyboard</h2>
  <h3>onkeydown - onkeyup</h3>
  <img src="" id="myImage"></img><br/><br/>
  <span>Key Pressed : <span id="kp"></span>
  <br />
  <span>Key Code : <span id="kc"></span>
  <p id="status">Keyboard Event Status</p>

  //here we are transforming the php $filelist array into a javascript array
  //by using the function `json_encode`
  //this must be done so as javascript is processed seperatly (on the client) to the php (which is done on the server).
  var files = <?php echo json_encode($filelist); ?>;

  var cIndex = 0;

  function displayNextImage(files){
    //here we check if the cIndex (current index) is less than the number of files. if it is, we can safely display the next image, and increment cIndex.
    if(cIndex < files.length){

  var isSaving = false;

  function saveKeyToServer(key){
    //here we send a "POST" request to out other script, savechar.php
    //savechar.php will simply write the pressed character into a file
    //we use a boolean value, isSaving, to track if a request is currently
    //in progress. This protects up from users spamming key presses before the new image loads.
    if(isSaving == false){
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
           //once the request has been resolved and the new image displayed,
           //we can safely process user input again
           isSaving = false;
      isSaving = true;
      xhttp.open("POST", "savechar.php", true);
      xhttp.send(JSON.stringify({"pressed" : key}));

  function displayImage(imageName){

  document.onkeydown = function(event) {
    var key_press = String.fromCharCode(event.keyCode);
    var key_code = event.keyCode;
    document.getElementById('kp').innerHTML = key_press;
    document.getElementById('kc').innerHTML = key_code;
    var status = document.getElementById('status');
    status.innerHTML = "DOWN Event Fired For : " + key_press;
    if(key_press == "Y"){
        document.body.style.background = "lime";
    } else if(key_press == "N") {
        document.body.style.background = "red";
    } else if(key_press == "M") {
        document.body.style.background = "yellow";

  document.onkeyup = function(event){
    var key_press = String.fromCharCode(event.keyCode);
    var status = document.getElementById('status');
    status.innerHTML = "UP Event Fired For : "+key_press;
    document.body.style.background = "white";

  //we call this here, so that the first image is displayed

  $pressed_key = json_decode(file_get_contents("php://input"),true)["pressed"];
  $fh = fopen("saved_chars.txt","a");
  fwrite($fh, $pressed_key);
Related Posts Related QUESTIONS :
  • How to sell Python to a client/boss/person
  • How to easily consume a web service from PHP
  • How to include PHP files that require an absolute path?
  • Multi-Paradigm Languages
  • PHP Error - Uploading a file
  • MySQL/Apache Error in PHP MySQL query
  • Lightweight IDE for Linux
  • How to search a row that has been joined with another table
  • How to do mysql LEFT JOIN for Google multiple line chart (php, mysql)?
  • Find the two longest strings separated by dash in PHP
  • Cannot access private property with Set method in Symfony
  • How to compare 2 array of PHP objects then fill in empty string if data not match?
  • strtotime gives back false result to strings in an array
  • How to create Url that contain name and id laravel
  • Codeigniter: Models not working with an error: Undefined property: CI_Loader
  • How to use + or - operators as parameters in Doctrine prepared SQL statement?
  • How to run scrapy with url parameters from php on linux debian
  • Preg matching imgur.com links
  • Php - Code comparing value of database to the value send by android app
  • Laravel pagination object in javascript
  • Error in validating message of no votes PHP
  • Symfony site on Azure with ClearDB connection
  • Woocommerce upsell with checkboxes
  • How to login/logout with Hybridauth 3?
  • Convert INT number in PHP
  • php/mysql. selecting 2 common fields in 2 tables
  • Expand an string based on values in an array in PHP
  • When you absolutely have to manually escape SQL in CakePHP 3.4.7
  • Htaccess redirecting wrong page
  • Laravel Optional WHERE clause
  • PHP unpack overlfow variable memory limit
  • How to check the URL's structure using PHP preg_match?
  • PHP preg_replace - text will not be recognized
  • Show image from other domain without showing the domain name - PHP
  • How to run and watch local server at the same time?
  • Access form request from Observer laravel
  • single quote problem with preg_replace_callback
  • How to Create A Unique URL for each product enquiry form for Google Analytics Tracking
  • Laravel email configuration: what am I missing?
  • Assign indexed array values to multidimensional array?
  • Custom WordPress stylesheet not loading
  • Data attribute only returning first value
  • How to list all roles with Permissions,in spatie permission Package?
  • How to achieve this number pattern with n input
  • How to iterate array inside array data in laravel ,output are given below
  • To get output of movie with its genre
  • Extracting some data from a JS object literal string in PHP using Regex
  • axios and vuex are deleting wrong index in array
  • Setting empty CURLOPT_POSTFIELDS
  • Laravel 5.8 use subdomain as API endpoint beside domain.com/api
  • Error while add data in database SQL Server 2016
  • Does PhpStorm allow to skip PHPDoc tags when type hints is declared?
  • html classes are changed to Attributes
  • Using json to import multidimensional data
  • passing data from the view to the controller, where the data comes from another controller
  • How to extract integer and decimal numbers in PHP string correctly?
  • Parsing Sub-Object from an XML Feed with objects
  • Getting error "Unknown column 'text' in 'field list'"
  • How to properly get onedrive access token via php and curl
  • How to add spell check to a php function
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com