473,788 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2400
On Fri, 14 Dec 2007 14:38:41 +0100, VooDoo <Vo*********@fr ee.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,$matc h);
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_EXTENS ION);

Micha
Dec 14 '07 #3
On Fri, 14 Dec 2007 19:18:41 +0100, Michael Fesser <ne*****@gmx.de wrote:
.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_EXTENS ION);
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
6552
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. Thanks Megha
6
5466
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? -- Els Mente humana é como pára-quedas; funciona melhor aberta.
3
2063
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 (C#) program to validate the xml file against the xsd file without any error. The problem is that when I validate the same xml file within VisualStudio 2003, I got five errors, which are all related to xsd:extension. It seems that those "problem"...
6
6670
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 = tdf.LastUpdated If Left(StrTblName, 3) <> "tbl" And tblAtt = 0 Then strSQL = "INSERT INTO tmpExport ( Code ) SELECT _
1
4079
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 click this link, the download window shows me the file name with a .ppt extension instead of the original .pps extension. I know both are Power Point files, but why IE changes the file extension? Is it a normal behaviour? TIA,
7
2922
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="*" path="*.sgf" type="CustomExtensionHandler, Extenders.CustomExtensionHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d831d925597c1031" validate="True"/> </httpHandlers>
1
2175
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) would return "Microsoft Word Document"... tired doing this before with SHGetFileInfo or what ever its called, but that seemed to require a phyiscal file to be there, where this you can just give it a file extension with no file. Private Function...
4
2534
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 error LNK1141: failure during build of exports file error: command '"C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe"' failed with exit status 1141.What shoud I
5
7967
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, it can open the file. However, when I run Php5 I (now) get this error message: "Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?" This is new. Last time I messed with this, I merely got:
8
7474
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 runtime...and to make matters worse users are allowed to use images in any format...so long as they have the filename that matches the property name. My problem stems from the fact that I dont know the extension of the file...only the filename...so...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2897
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.