23 September 2019

how to upload image file in database in php in wordpress?

upload image file in database in php in wordpress



<html>
<head>


<?php


extract($_POST);
global $wpsite;
global $wpdb;
if(isset($_POST['submit'])){

/* Upload  Image */
if ( ! function_exists( 'wp_handle_upload' ) )
          require_once( ABSPATH . 'wp-admin/includes/file.php' );
          $uploadedfile = $_FILES['file'];
          $upload_overrides = array( 'test_form' => false );
          $movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
          if ( $movefile ) {
              //var_dump( $movefile );
  //echo $movefile['url'];
      } else {
             echo "Possible file upload attack!\n";
}

$downloadlink = $movefile['url'];
$menutable=$wpdb->prefix.$wpsite."_menutable";
$wpdb->insert($menutable, array('item_name' => $itemname, 'item_type' => $itemtype, 'item_catagory' => $itemcata, 'meal' => $meal, 'price' => $price, 'status' => $status, 'restaurant_id' => $restaurantid,'download_link' => $downloadlink ) );

}
?>


</head>
<body>
<form action="" method="post" enctype="multipart/form-data" >
<input type="text" name="restaurantid" placeholder="restaurant_id">
<input type="text" name="itemname" placeholder="Item Name">
<input type="text" name="itemtype" placeholder="Item Type">
<input type="text" name="itemcata" placeholder="Item Catagory">
<input type="text" name="meal" placeholder="Meal">
<input type="text" name="price" placeholder="Price">
<input type="text" name="status" placeholder="Status">
<input type="file" name="file" id="file" class="form-upl">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

No comments:

Post a Comment

How to add re-captcha v3 on all Elementor forms using coding?

 Add re-captcha v3 on all Elementor forms using coding add_action('wp_footer',function(){     ?> <script src="https://www...