CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
determining file extension of uploaded image

 



kencl
User

Feb 11, 2001, 1:03 PM

Post #1 of 4 (2290 views)
determining file extension of uploaded image Can't Post

I havn't worked with regular expressions much, so this is probably pretty easy. I'm trying to get the extension of an uploaded image file. I tried this, but it just stripped the drive letter:

Code
$filehandle = $q -> param("pic"); 
$extension = substr($filehandle, $filehandle =~ /.(gif|jpg|jpeg)$/i);

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!


kencl
User

Feb 11, 2001, 6:09 PM

Post #2 of 4 (2288 views)
Re: determining file extension of uploaded image [In reply to] Can't Post

I figured it out. I'm posting it just so others can see how I did it.

Code
$imageHTML = "\&nbsp\;";  # when there's no image uploaded, put a space into the cell 
$filehandle = $q -> param("featuredpic");
if (defined($filehandle)) {
if ($filehandle =~ /(gif|jpg|jpeg)$/i) {
$imageHTML = "<img src='featuredimages/featuredpic".$featuredpageindex.".".$+."'>";
$imagefile = "../../../www/bc/featuredimages/featuredpic".$featuredpageindex.".".$+;
open(SAVEIMAGE, ">$imagefile");
while (<$filehandle>) {
print SAVEIMAGE $_;
}
close (SAVEIMAGE);
}
}

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!


Jean
User


Feb 20, 2001, 10:15 AM

Post #3 of 4 (2270 views)
Re: determining file extension of uploaded image [In reply to] Can't Post

Use something like that:

if ( $filehandle =~ /\.(gif|jpg|jpeg)$/i ) {
$extension = $1;
}

Note: $extension is left undefined in case the extension it one of the checked...


Jean
QA Engineer @ http://www.extent.com
mage@lycosmail.com


Jean
User


Mar 7, 2001, 8:30 AM

Post #4 of 4 (2258 views)
Re: determining file extension of uploaded image [In reply to] Can't Post

Sorry, when I started writing the reply, I haven't seen you post yet Blush

Jean Spector
QA Engineer @ Extent Technologies, Ltd.
mage@lycosmail.com

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives