Search
 
SCRIPT & CODE EXAMPLE
 

PHP

code on editing an image in database in php

<?php
include("config.php");

if(isset($_POST['but_upload'])){
 
  $name = $_FILES['file']['name'];
  $target_dir = "upload/";
  $target_file = $target_dir . basename($_FILES["file"]["name"]);

  // Select file type
  $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

  // Valid file extensions
  $extensions_arr = array("jpg","jpeg","png","gif");

  // Check extension
  if( in_array($imageFileType,$extensions_arr) ){
    // Upload file
    if(move_uploaded_file($_FILES['file']['tmp_name'],$target_dir.$name)){
       // Convert to base64 
       $image_base64 = base64_encode(file_get_contents('upload/'.$name) );
       $image = 'data:image/'.$imageFileType.';base64,'.$image_base64;
       // Insert record
       $query = "insert into images(image) values('".$image."')";
       mysqli_query($con,$query);
    }
    
  }
 
}
?>

<form method="post" action="" enctype='multipart/form-data'>
  <input type='file' name='file' />
  <input type='submit' value='Save name' name='but_upload'>
</form>
Comment

PREVIOUS NEXT
Code Example
Php :: PHP str_getcsv — Parse a CSV string into an array 
Php :: how to lookup value object php 
Php :: require_once in class php 
Php :: keep multiple values in select box after reload in php 
Php :: To fetch the soft deleted user, you should use withTrashed 
Php :: Right triangle start pattern of star 
Php :: create json file in php and write n php 
Php :: PHP Number Shortener 
Php :: wp retrieve acf by category name 
Php :: send email to no register user in laravel 
Php :: crc32 (PHP 4 = 4.0.1, PHP 5, PHP 7, PHP 8) crc32 — Calculates the crc32 polynomial of a string 
Php :: php formula return more results 
Php :: appserviceprovider laravel share common settings for all controllers 
Php :: symfony postgresql 
Php :: can i do a relation between 2 coulnm in mongodb laravel 
Php :: php check bracket correct open and close 
Php :: concat ternary operator 
Php :: virtual fields cakephp 4 
Php :: @parent, @include, @show blade in laravel 
Php :: jobs laravel 
Php :: how to make text bigger in php file 
Php :: wp $product add alt 
Php :: php get list of months by year 
Php :: magento 2 create group programmatically 
Php :: Call to a member function move() on null 
Php :: laravel capitalize first letter 
Php :: larave per page int returns string 
Php :: how to call a function in model from a controller 
Php :: undefined type excel 
Php :: auto check a category when creating new post 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =