How to get image name from image path in php?

I am trying to display an image with a caption and thumbnails. I am able to display the picture but I am finding difficult to display the image file name as caption.

Below is my code:

  


    var slideIndex = 1;
    showDivs[slideIndex];
    function plusDivs[n] {
        showDivs[slideIndex += n];
    }
    function showDivs[n] {
        var i;
        var x = document.getElementsByClassName["mySlides"];
        if [n > x.length] {slideIndex = 1}
        if [n < 1] {slideIndex = x.length}
        for [i = 0; i < x.length; i++] {
            x[i].style.display = "none";
        }
        x[slideIndex-1].style.display = "block";
    }

halfer

19.6k17 gold badges92 silver badges175 bronze badges

asked Sep 30, 2016 at 10:43

To show caption set title attribute. And set name of image in tile attribute.

To get Image name from fullpath of Image use basename[$num]

Please replace your php code with below.

echo ''."  "; 

To get filename without extension for every image place below code in loop. And place $filename variable where you want to display image name.

$filenamewithextension = basename[$num];
$fileextenstion = pathinfo[$filenamewithextension, PATHINFO_EXTENSION];
$filename = basename[$num,$fileextenstion];
$filename = trim[preg_replace['/[0-9]+/', '', $filename]];

answered Sep 30, 2016 at 10:49

Rahul PatelRahul Patel

5,1782 gold badges13 silver badges25 bronze badges

10

It’s very easy and simple. We need to Create Database for storing the user data. and write PHP script to get user data from the form and stored into database. We have provided all files and DB below of this blog.

Let’s Create Database Using PhpMyadmin

  • Go to in phpmyadmin [localhost/phpmyadmin]
  • Login into phpmyadmin [Default user: root ,and pass: [NULL]]
  • After redirected on phpmyadmin dashboard will look like this.
phpmyadmin [Mysql] Dashboard
Fill database name and click on create | Database Creating.
  • Create table in this database here “users
  • Put numbers of field you want to create here “4″
Table name with 4 columnsProper datatype and name of column

Write PHP script, to upload image and get stored into DB

User Data form along with profile picture

File name: index.php



Add User




  Name  : 
Email :
Profile Picture:

FIle Name upload.php

Chủ Đề