-1

I need to encode a file before i include it to the bank with the code below:

    $file = 'CT0001_0002.1.jpg';
    $validate = pathinfo($file, PATHINFO_EXTENSION);
    list($name,$extension) = explode($validate,$file);
    $date = date("Y-m-d H:i");
    $cod = md5($name.$date).".".$extension;
    echo $cod;

When I print, it returns like this:

6ab87875286005866f0504961fc2438c.

Without the extension. Pathinfo() is enabled on the server. He should return:

6ab87875286005866f0504961fc2438c.jpg
JM_2021
  • 165
  • 6
  • 1
    Does this answer your question? [How do I get a file name from a full path with PHP?](https://stackoverflow.com/questions/1418193/how-do-i-get-a-file-name-from-a-full-path-with-php) – DevWithZachary Oct 08 '21 at 12:38

1 Answers1

2

pathinfo already provides all the details you'd need:

<?php

$file = 'CT0001_0002.1.jpg';
$validate = pathinfo($file);
$date = date("Y-m-d H:i");

$cod = md5($validate['filename'] . $date) . "." . $validate['extension'];
echo $cod;

print_r($validate) would output:

Array
(
    [dirname] => .
    [basename] => CT0001_0002.1.jpg
    [extension] => jpg
    [filename] => CT0001_0002.1
)
brombeer
  • 8,716
  • 5
  • 21
  • 27