Images - JWalshe86/nags-with-notions4 GitHub Wiki

Bug - Images not centered on mobile screen

image

Using Card Decks:

<div class="card-deck">
  <div class="card">
    <img class="card-img-top" src="..." alt="Card image cap">
    <div class="card-body">
      <h5 class="card-title">Card title</h5>
      <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
      <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
    </div>
  </div>
  <div class="card">
    <img class="card-img-top" src="..." alt="Card image cap">
    <div class="card-body">
      <h5 class="card-title">Card title</h5>
      <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
      <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
    </div>
  </div>
  <div class="card">
    <img class="card-img-top" src="..." alt="Card image cap">
    <div class="card-body">
      <h5 class="card-title">Card title</h5>
      <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
      <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
    </div>
  </div>
</div>

Using img-responsiveness class

Took this code from stackoverflow_answer:

<div class="container">
    <div class="col-md-4 px-0">
        <img src="images/food1.jpg" class="img-fluid">
    </div>
</div>

img-fluid didn't work but img-responsive did. This is because I'm using bootstrap 3.4.1 looks much better image

All images looking better on mobile image Code:

<div class="card-deck">
  <div class="container">
     <div class="col-md-4" style="padding-left: 0px;  padding-right: 0px;">
        <img src="media/margherita-for-mares.jpg" alt="Card image cap" class='img-responsive'>
        <h5 class="card-title">Card title</h5>
        <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
     </div>
   </div>
  <div class="container">
     <div class="col-md-4" style="padding-left: 0px;  padding-right: 0px;">
        <img src="media/no-animals-here-resized.jpg" alt="Card image cap" class='img-responsive'>
        <h5 class="card-title">Card title</h5>
        <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
     </div>
   </div>
  <div class="container">
     <div class="col-md-4" style="padding-left: 0px;  padding-right: 0px;">
        <img src="media/pony_soprano.jpg" alt="Card image cap" class='img-responsive'>
        <h5 class="card-title">Card title</h5>
        <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
     </div>
   </div>
  <div class="container">
     <div class="col-md-4" style="padding-left: 0px;  padding-right: 0px;">
        <img src="media/feeling_blue.jpg" alt="Card image cap" class='img-responsive'>
        <h5 class="card-title">Card title</h5>
        <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
     </div>
   </div>
  <div class="container">
     <div class="col-md-4" style="padding-left: 0px;  padding-right: 0px;">
        <img src="media/horse-to-france.jpg" alt="Card image cap" class='img-responsive'>
        <h5 class="card-title">Card title</h5>
        <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
     </div>
   </div>
  <div class="container">
     <div class="col-md-4" style="padding-left: 0px;  padding-right: 0px;">
        <img src="media/sauces.jpg" alt="Card image cap" class='img-responsive'>
        <h5 class="card-title">Card title</h5>
        <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
     </div>
   </div>
</div>

Going to adapt the following video into the img cards bootstrap responsive cards

  • Wrapping all content in a container div to make it responsive
  • Wrap all the columns in a row
  • Used imagy.app to make all images 2:3 ratio
  • Had to change img class back from card-img-top to img-responsive
  • Setting class="col-lg-4 col-12 col-md-6" for each card made them responsive on all screens
  • Used g for gutter in row to create space between cards <div class="row g-3">

Need to resize 3 of the images image

Resized the images image

3 images are blurry though image

Better on mobile image

Removed blurry images image

Insert images using mysql

Going to try insert images to MYSQL

This is the db_conn.php code:

<?php  

$sname = "localhost";
$uname = "root";
$password = "Sunshine7!";

$db_name = "ol5wws00_image_db";

/* The mysqli_connect() function establishes a connection with MySQL server and returns the connection as an object.
*/
$conn = mysqli_connect($sname, $uname, $password, $db_name);

if (!$conn) {
	echo "Connection failed!";
	exit();
}

when use PDO or mysqli_connect?

Test for upload with upload.php works image

image image

image

🎉 Image uploads successfully image

Created test_db image Table image

image

🐛 Locked self out of phpmyadin: generated change password for root & couldn't recall password generated & uninstalled LAMPP

Reinstalled XAMPP image

Back in: image

DBs still there image

🎉 Back working for CRUD image

Get root permissions error image

Getting this error now: image

Images uploading again: image

Changed root password to Sunshine7! and set password to Sunshine7! in db_conn.php Get this error image I had the image table spelt incorrectly 🎉 image

image

connect & query mysql

PDO to mysqli_connect

Set upload.php & view.php to connection.php Images uploading to 'uploads' folder image But not showing in views.php

When upload.php includes the db_conn db it redirects to views.php but this doesn't happen when using connection.php. I think this part is failing image I think it fails because mysqli_query doesn't work on PDO which connection.db uses

CREATE TABLE `users` (
`id` INT( 5 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`image` VARCHAR( 25 ) NOT NULL
)

Image uploaded successfully to uploads file

<table border="2">
<tr>
<th>ID</th>
<th>Image</th>
</tr>
<?php
include "connect.php";
$select = $con->prepare("SELECT * FROM users ");
$select->setFetchMode(PDO::FETCH_ASSOC);
$select->execute();
while($data=$select->fetch()){
?><tr>
<td><?php echo $data['id']; ?></td>
<td><img src="uploads/<?php echo $data['image']; ?>" width="100" height="100"></td>
<?php
}?>
</tr></table>
<a href="index.php">Add new image</a>

only uploading one image & select.php doesn't work

Images upload image# Only upload with:

<?php

try{
$con = new PDO ("mysql:host=localhost;dbname=imageupload","root",""); 
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "connected";
}
catch(PDOException $e)
{
echo "error:".$e->getMessage(); 
}

?>

Both tables work in same db 🎉 image

Superuser ability to add images

This code selects only passwords with the value 'test'

<?php
        require('./connection.php');
            $p=crud::Selectdata();
            if (isset($_GET['id'])) {
                $id=$_GET['id'];
                $e=crud::delete($id);
            }
            if (count( $p)>0) {
                for ($i=0; $i < count( $p); $i++) { 
                   echo '<tr>';
                   foreach ( $p[$i] as $key => $value) {
                        if ($value == 'test'){
                        echo '<td>'.$value.'</td>';
                          }
                    }
                    ?>

may look into checking if user is logged in 🎉 Session login messaged displayed image closed sessiong using google chromes - inspect - application - cookies - https://localhost - phpSESSID - delete image

<?php
session_start();

          if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
               echo "Welcome to the member's area, " . htmlspecialchars($_SESSION['name']) . "!";
          } else {
              echo "Please log in first to see this page.";
               }
      $url = "index.php";
      echo "<a href='$url'>Add new Image</a>";
    ?>

🎉 got upload image btn working in php code using echo to print out html image

image

Used How to add a href link in php

$url = "https://www.google.com/";

echo "<a href='$url'>Google</a>";

This produces html output

image

Image gallery with mysqli

Going to make image gallery using mysqli instead- shows had to create dynamic images with bootstrap

All CDNS appear to work in index.html

Modal presents on screen

image

Connected successfully image

Converter function works on chrome but not microsoft internet image Gives a chrome extension invalid error image

$(function() {
 
      // Validate image in client side
      $("#image_upload").change(function (e) {
         let file_ext = $(this).val().split(".").pop().toLowerCase();
         let allowed_ext = ["jpg", "jpeg", "png"];
         let file_size = this.files[0].size;
 
         if(allowed_ext.includes(file_ext)){
            if(file_size <= 1000000){
              let url = window.URL.createObjectURL(this.files[0]);
              $("#preview_image").html(`<img src="${url}" class="img-fluid img-thumbnail">`);
           }

        }
     });
 });               

Image preview working image

Image size too big working & upload button disabled image

Error message for incorrect img types working image

Array data associated to image displays image

🎉 Images uploading to db & uploads folder image image

image

Progress bar working image

Ajax testing successfull image

fetch_all_images function gathering all the images data image

wrapped image output in html image

All images uploading successfully image

Modal presents image

Image object info shows on click image

Modal pops up with image on click image

Change image modal presents image

Ajax response for edit image data successful image

Previous values on edit present image

Change images array displaying - old & new img data image

🎉 Image updated successfully image

// Remove image ajax request
	
	$(".remove_image").click(function (e){
          e.preventDefault();
	  let id = $(this).attr('data-id');
          let img_url = $("#set_image").attr("src");
	  $.ajax({
            url: 'action.php',
            method: 'post',
            data: { id:id, img_url:img_url, remove_image:1 },
            success:function(response){
	      image_modal.hide();
	      fetchAllImages();
	      $("#delete_image_alert").html(response);
	    },
	  });
	});
// Handle remove image ajax request
   if(isset($_POST['remove_image'])){
     $id = $_POST['id'];
     $img_url = $_POST['img_url'];

     if($db->removeImage($id)){
       unlink($img_url);
       echo $util->showMessage('success','Image deleted successfully!');
     }else{
        echo $util->showMessage('danger', 'Something went wrong!');
     }

   }  
In Database.php
// Delete image method
  public function removeImage($id){
    $sql = 'DELETE FROM gallery WHERE id = :id';
    $stmt = $this->conn->prepare($sql);
    $stmt->execute(['id' => $id]);
    return true;
  }
  }

🎉 Image deleted successfully image

🎉 Image crud functionality working on deployed cpanel site

⚠️ **GitHub.com Fallback** ⚠️