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.
$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.
Use PHP basename() function.
string basename ( string $path [, string $suffix ] )
Yes, you can do it as:
$filenameOnly = array_pop(array_reverse(explode(".", $yourfilename)));
Hope that helps
preg_replace('^(.*)\..+?$', $_FILES['file']['name']);
Try basename or use a regex to do it indiscriminately:
preg_replace('/(.*)\\.[^\\.]*/', '$1', $filename);
Use pathinfo()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With