Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file name without extension [duplicate]

Tags:

php

Is there any method of obtaining the name of the file uploaded to a server without extension, in PHP? I used the $_FILES['file']['name'] but it returns the extension too.

like image 266
chetan Avatar asked Nov 14 '11 15:11

chetan


6 Answers

$filename = pathinfo($_FILES['file']['name'], PATHINFO_FILENAME);

pathinfo is a core PHP function since 4.0.3, and the PATHINFO_FILENAME option was added in 5.2.

like image 51
Marc B Avatar answered Oct 18 '22 02:10

Marc B


Use PHP basename() function.

string basename ( string $path [, string $suffix ] )
like image 43
Riz Avatar answered Oct 18 '22 02:10

Riz


Yes, you can do it as:

$filenameOnly = array_pop(array_reverse(explode(".", $yourfilename)));

Hope that helps

like image 21
Sudhir Bastakoti Avatar answered Oct 18 '22 03:10

Sudhir Bastakoti


preg_replace('^(.*)\..+?$', $_FILES['file']['name']);
like image 44
rid Avatar answered Oct 18 '22 03:10

rid


Try basename or use a regex to do it indiscriminately:

preg_replace('/(.*)\\.[^\\.]*/', '$1', $filename);
like image 1
Godwin Avatar answered Oct 18 '22 02:10

Godwin


Use pathinfo().

like image 1
CodeCaster Avatar answered Oct 18 '22 02:10

CodeCaster