0

I add file input directory address from kcfinder to html input value like this:

/user/uploads/files/video/slider-bg2.jpg

Now I need to only file name with extension (like: slider-bg2.jpg) to insert to MySQL database. How can I remove or separate /user/uploads/files/images/ from slider-bg2.jpg?

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Pink Code
  • 1,802
  • 7
  • 43
  • 65

2 Answers2

0

you can try

SUBSTRING_INDEX("/user/uploads/files/video/slider-bg2.jpg","/",-1)

in mysql

SO

INSERT INTO table(columnname) values (SUBSTRING_INDEX("$yourFullFileNameWithDirectories","/",-1)
Tin Tran
  • 6,194
  • 3
  • 19
  • 34
0

Use PHP’s pathinfo to get the dirname & basename from the full path provided & act on it accordingly.

$fullpath = '/user/uploads/files/video/slider-bg2.jpg';

echo '<pre>';
print_r(pathinfo($fullpath));
echo '</pre>';

The output would be:

Array
(
    [dirname] => /user/uploads/files/video
    [basename] => slider-bg2.jpg
    [extension] => jpg
    [filename] => slider-bg2
)

So you can then access the directory name by $fullpath['dirname'] and the filename by $fullpath['basename'].

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103