How to alter an uploaded image resolution using PHP before storing in mysql BLOB field -


i have created mysql database 'tutorial_db' , in database have created table 3 columns:

the image table in tutorial_db

i have written following code using php , html upload image file , store in longblob 'image' column , display images database in same page:

<?php //connect database $con = mysqli_connect('localhost', 'root', '', 'tutorial_db') or die('could not connect database: '.mysqli_connect_error()); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>upload image</title> </head> <form action="image.php" method="post" enctype="multipart/form-data"> <p><input type="file" name="image"></p> <p><input type="submit" name="upload_image" value="upload"></p> </form> <?php error_reporting(0); if(isset($_post['upload_image'])) {     //check if image file uploaded or not.     if(getimagesize($_files['image']['tmp_name']) == false) {         //this block executed if non-image file or no file uploaded         echo 'please upload image!';      } else {         //this block executed if image uploaded         $image = addslashes(file_get_contents($_files['image']['tmp_name']));         $image_name = addslashes($_files['image']['name']);          //query insert images in table         if(!mysqli_query($con, "insert image(image_name, image) values('$image_name', '$image')")) {             echo "failed upload image!";         }     }     //query display images stored in image database     $record = mysqli_query($con, "select * image");     while($rows = mysqli_fetch_assoc($record)) {         echo '<img width = "20%" height = "200px" src="data:image/jpeg;base64,'.base64_encode( $rows['image'] ).'"/>';     }     mysqli_close($con); }  ?> <body> </body> </html> 

it working fine images resolution lower 1920x1080. when try uploading images of resolution, example: 3840x2160 displays uploading failed error. guessing due image resolution error being displayed. there way reduce resolution of such images before storing them in mysql database?


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -