delete extension from filename

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 23
Joined: Tue Jun 24, 2003 4:49 am

Fri Jun 27, 2003 3:53 am


When you do the test to know whether it is a .jpg file or not, you use the function substr...
substr returns a string but does not alter the string you pass as an argument.
In other words, calling substr($nomfichier, -3) will not change anything in the variable $nomfichier... And when you use it later, you will therefore still have the full name with the extension...

To solve the problem, try like this

Code: Select all

$fichiers .= ",".substr($nomfichier, 0, strlen($nomfichier) - 4); // I guess you do not want the dot either...

There is another thing, you should perhaps be sure that the file you are currently processing is not a directory with the function is_dir...


Post Reply