1

I have a webpage where user can upload as many image they like. When the user upload the image it show those image on the website (so user know what they are uploading) but, it should has a number "next to" image. This should be before the user submit the images. As I have a description box (after the image upload text I removed from this code though, but please assume its just a textarea after imageupload tags), so user can tell image "1" means this or that etc. How can I add those numbers to identify the image?

How to show the number next to image when the user upload the images, so the description user write such as "picture 1 means that, picture 2 means that etc" will make sense to users.

I am using php, bootstrap, javascript, html, css for it.

My code:

<?php require "navigationbar.php"; ?>
<html>
<head>
<link 
rel="stylesheet" 
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Raleway:wght@100&display=swap" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="login-container" >
<form action="./backend/Backend.php"  method="post">
  </div>
  <div class="form-group row">
    <div class="col-sm-10">
      <input type="text" class="form-control" >
    </div>
  </div>
  <div class="form-group row">
    <div class="col-sm-10" >
      <input type="file" multiple id="gallery-photo-add" class="btn btn-primary btn-sm float-left"  >
      <div class="gallery"></div>
    </div>
  </div>
  <div class="form-group row">
    <div class="col-sm-10">
      <button type="submit" class="btn btn-primary" >Submit</button>
    </div>
  </div>
</form>
</div>
<script>
    
    $(function() {
        // Multiple images preview in browser
        var imagesPreview = function(input, placeToInsertImagePreview) {    
            if (input.files) {
                var filesAmount = input.files.length;    
                for (i = 0; i < filesAmount; i++) {
                    var reader = new FileReader();    
                    reader.onload = function(event) {
                        $($.parseHTML('<img>')).attr('src', event.target.result).appendTo(placeToInsertImagePreview);
                    }    
                    reader.readAsDataURL(input.files[i]);
                }
            }
    
        };    
        $('#gallery-photo-add').on('change', function() {
            imagesPreview(this, 'div.gallery');
        });
    });
    
    </script>
</body>
</html>

How can I add number next to images? If any other detail is needed please let me know. I can provide more code or information related to it. Thanks.

I found a similar question: Adding number label on top of an image

But this one puts the number next to image not while uploading the image.But, that's what I am looking for as in the above question they have a green box with number next to image. For my question I want it to display after user selects image and it shows on the website but "with" those numbers. Can anyone reckon something?

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
  • Add your PHP / Javascript code – Chilarai Jul 26 '20 at 04:20
  • @Chilarai I have updated my question with more code. Please have a look –  Jul 26 '20 at 05:29
  • There is no php code here. Do you want the number to be added in the client (javascript) or in the server (php)? – Mosh Feu Jul 26 '20 at 10:32
  • @MoshFeu I want it to add while the user upload (that can be done using javascript I believe) but it should appear after they upload the images so I guess maybe using PHP –  Jul 27 '20 at 03:50
  • You might be able to do this on the client with javascript using `canvas`. Check this out: https://stackoverflow.com/a/41117085/863110 – Mosh Feu Jul 27 '20 at 07:00

0 Answers0