473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

get extension of a file

Hi all,
I used to use this for getting the extension of an uploaded file..
$ext = strstr($doc, ".");

but apparently this not work when the filename contain a '.'

What is the best way to get the correct extension of a file???
Thanks for your suggestion.
VooDoo

Dec 14 '07 #1
3 2366
On Fri, 14 Dec 2007 14:38:41 +0100, VooDoo <Vo*********@free.frwrote:
Hi all,
I used to use this for getting the extension of an uploaded file..
$ext = strstr($doc, ".");

but apparently this not work when the filename contain a '.'

What is the best way to get the correct extension of a file???
Thanks for your suggestion.
preg_match('/\.([^.]+)$/',$string,$match);
or
strrchr($string,'.');
--
Rik Wasmus
Dec 14 '07 #2
..oO(VooDoo)
>Hi all,
I used to use this for getting the extension of an uploaded file..
$ext = strstr($doc, ".");

but apparently this not work when the filename contain a '.'

What is the best way to get the correct extension of a file???
$ext = pathinfo($doc, PATHINFO_EXTENSION);

Micha
Dec 14 '07 #3
On Fri, 14 Dec 2007 19:18:41 +0100, Michael Fesser <ne*****@gmx.dewrote:
.oO(VooDoo)
>Hi all,
I used to use this for getting the extension of an uploaded file..
$ext = strstr($doc, ".");

but apparently this not work when the filename contain a '.'

What is the best way to get the correct extension of a file???

$ext = pathinfo($doc, PATHINFO_EXTENSION);
Ah, that's what I was looking for, thank you. Kept ending up in the finfo*
functions for some reason (which are commonly more usefull then extensions
offcourse).
--
Rik Wasmus
Dec 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: megha | last post by:
Hi all I am exporting some data in .csv format through jsp file it is exporting the data in csv format but giving the exported file .jsp extension. I want .csv extension can anybody help. ...
6
by: Els | last post by:
If I use <? include "file.html"; ?> in the html of my document, do I _have_ to change the extension of that document to .php, or would it still work and be valid if I let it remain .html? --...
3
by: man-in-nature | last post by:
Hello, I have already read several existing posts about xsd:extension, but do not find something useful to my test case. I have one xml file and one xsd file. I can use a simple command line...
6
by: J. Shrimp, Jr. | last post by:
Following code exports tables as text files: For Each tdf In db.TableDefs StrTblName = tdf.Name Me.txtProgName = StrTblName Me.txtProgName.Requery tblAtt = tdf.Attributes moddate =...
1
by: Erik Cruz | last post by:
Hi. My application has a page where users can click on some links to download documents. When testing the page I noticed an strange behaviour. One of the links points to a .pps file. When I...
7
by: Adam | last post by:
Im trying to add an httphandler for all *.sgf file extensions. I have developed the handler, 1. installed it into the gac 2. added it to the machine.config: <httpHandlers> <add verb="*"...
1
by: Brian Henry | last post by:
Just thought maybe someone here would like to know this. It's an example code I just created quickly on how to figure out the name of a type of file based on its extension (say for example .DOC)...
4
by: vedrandekovic | last post by:
Hi, I have already install Microsoft visual studio .NET 2003 and MinGw, when I try to build a extension: python my_extension_setup.py build ( or install ) , I get an error: LINK : fatal...
5
by: Chuck Anderson | last post by:
I run Apache 2.0.55, and Php (both 4.4.1 and 5.2.5) on my home PC (Windows XP). One of the scripts that I run daily needs to access a secure URL (https://..............). When I am running Php4,...
8
by: Ron | last post by:
I am building a dynamic image loading class. I have a list of properties that have associated images in a specified directory. The problem they are multiple formats which are not known at...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.