/*Create table in sql:*/ CREATE TABLE `images` ( `id` int(11) NOT NULL AUTO_INCREMENT, `image` longblob NOT NULL, `created` datetime NOT NULL, PRIMARY KEY (`id`) ); /*Uploading an image to Database*/ <?php if(isset($_POST["submit"])){ $check = getimagesize($_FILES["image"]["tmp_name"]); if($check !== false){ $image = $_FILES['image']['tmp_name']; $imgContent = addslashes(file_get_contents($image)); $dbHost = 'localhost'; $dbUsername = 'root'; $dbPassword = 'root'; $dbName = 'sample'; //Create connection and select DB $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName); // Check connection if($db->connect_error){ die("Connection failed: " . $db->connect_error); } $dateTime = date("Y-m-d H:i:s"); //Insert image content into database $insert = $db->query("INSERT into images_tbl (image,created) VALUES ('$imgContent', '$dateTime')"); if($insert){ echo "File uploaded successfully."; }else{ echo "File upload failed, please try again."; } }else{ echo "Please select an image file to upload."; } } ?> <form action="" method="post" enctype="multipart/form-data"> Select image to upload: <input type="file" name="image" required /> <input type="submit" name="submit" value="UPLOAD"/> </form> /*Retrieve an image from database*/ <?php if(!empty($_GET['id'])){ //DB details $dbHost = 'localhost'; $dbUsername = '****'; //give your database name here $dbPassword = '****'; //give your database password here $dbName = 'sample'; //Create connection and select DB $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName); //Check connection if($db->connect_error){ die("Connection failed: " . $db->connect_error); } //Get image data from database $result = $db->query("SELECT image FROM images_tbl WHERE id = {$_GET['id']}"); if($result->num_rows > 0){ $imgData = $result->fetch_assoc(); //Render image header("Content-type: image/jpg"); echo $imgData['image']; }else{ echo 'Image not found...'; } } ?>
1.Install ssmtp as $ sudo apt-get update && sudo apt-get install ssmtp 2.Configure smtp file by editing the following file as, $ sudo gedit /etc/ssmtp/ssmtp.conf Update file with the following: AuthUser=Sendermail@gmail.com AuthPass=SenderPasswordforGMAIL FromLineOverride=YES mailhub=smtp.gmail.com:587 UseSTARTTLS=YES Now ssmtp.conf file should look like as the following one, AuthUser=Sendermail@gmail.com AuthPass=SenderPasswordforGMAIL # # Config file for sSMTP sendmail # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. root=postmaster # The place where the mail goes. The actual machine name is required no # MX records are consulted. Commonly mailhosts are named mail.domain.com mailhub=smtp.gmail.com:587 # Where will the mail seem to come from? #rewriteDomain= # The full hostname hostname=tele-desktop118 # A...
Comments
Post a Comment