Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove file extension on file upload

I'm writing the code for a website right now that's uploads images and then displays them gallery style. What I would like to happen is for the file name of the image to be entered into the site's database as the name of the image. However, just using $_FILES['images']['name']; gives me the file name but with the file extension attached at the end. How would I remove the file extension so I can use the file name by itself?

like image 927
codedude Avatar asked Jan 01 '26 01:01

codedude


1 Answers

You can use the pathinfo() function (docs).

$example  = "my_file.jpeg";
$filename = pathinfo($example, PATHINFO_FILENAME);
echo $filename; // my_file
like image 68
salathe Avatar answered Jan 02 '26 15:01

salathe