Skip to main content

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>

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...