Remove file extension on file upload

不问归期 提交于 2019-12-01 00:18:57

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

$example  = "my_file.jpeg";
$filename = pathinfo($example, PATHINFO_FILENAME);
echo $filename; // my_file

Just use preg_replace:

$name = preg_replace('/(.+)\.\w+$/U', $_FILES['images']['name'], '$1');

You can use rename to remove the extension:

-> http://www.php.net/manual/en/function.rename.php

As my comment above implies, it depends on what you consider in the filename to be the name and what is the extension.

everything up to the last dot:

$filename = 'some.file.name.zip';
$name = substr($filename, 0, strrpos($filename, '.'));

everything up to the first dot:

$filename = 'some.file.name.zip';
$name = substr($filename, 0, strpos($filename, '.'));

they look the same, but the first one looks for the first dot from the end of the string and the second one from the start of the string.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!