Joined: May 2002
Posts: 48
Member
Member
Joined: May 2002
Posts: 48
Anyone know how I would go about checking for a files's extension in perl ?
Joined: Jan 2000
Posts: 5,073
Admin Emeritus
Admin Emeritus
Joined: Jan 2000
Posts: 5,073
my $filename = "whatever.txt.ext"; my @components = split(/./, $filename); my $real_extension = $components[-1]; That should do the trick.
UBB.classic: Love it or hate it, it was mine.
Joined: May 2002
Posts: 48
Member
Member
Joined: May 2002
Posts: 48
So to check for the extension in a if statement I would use something like if ($real_extension = "ext") ?
Joined: Mar 2001
Posts: 7,394
Admin / Code Breaker
Admin / Code Breaker
Joined: Mar 2001
Posts: 7,394
instead of '=' use 'eq'...
code:
if ($real_extension eq 'ext') { You can also do, instead of all that:
code: [qb]if ($filename =~ m/.ext$/) { [/qb]
Joined: Aug 2000
Posts: 335
Member
Member
Joined: Aug 2000
Posts: 335
And if you want the check to be case-insensitive:
if ($filename =~ m/.ext$/i) {
Joined: May 2002
Posts: 48
Member
Member
Joined: May 2002
Posts: 48
Ok Im trying to do this within public_topic_page.pl
my $filename = $user_profile[20]; my @components = split(/./, $filename); my $real_extension = $components[-1]; if (($filename =~ m/.jpg$/i) || ($filename =~ m/.gif$/i)){ chomp($user_profile[20]); $user_profile[20] = "" if (($user_profile[20] eq 'http://') || ($user_profile[20] =~ /cp.cgi/ || /ultimatebb.cgi/ || /</)); my $this_img = ($user_profile[20] eq "") ? '' : qq! <img src="$user_profile[20]" alt="" /> !; } if ($filename =~ m/.swf$/i) { chomp($user_profile[20]); $user_profile[20] = "" if (($user_profile[20] eq 'http://') || ($user_profile[20] =~ /cp.cgi/ || /ultimatebb.cgi/ || /</)); my $this_img = ($user_profile[20] eq "") ? '' : qq! <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="120" height="120"> <param name=movie value="$user_profile[20]"> <param name=quality value=high> <embed src="$user_profile[20]" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="120" height="120"> </embed> </object> !; } Doesn't seem to work though...This is based on the external avatar hack thing
Joined: May 2000
Posts: 1,356
Addict
Addict
Joined: May 2000
Posts: 1,356
try this one:
my $filename = chomp($user_profile[20]); my $this_img; if (($filename =~ m/.jpg$/i) || ($filename =~ m/.gif$/i)){ $this_img = qq! <img src="$filename" alt="" /> !; } if ($filename =~ m/.swf$/i) { $this_img = qq! <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="120" height="120"> <param name=movie value="$filename"> <param name=quality value=high> <embed src="$filename" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="120" height="120"> </embed> </object> !; }
Joined: May 2002
Posts: 48
Member
Member
Joined: May 2002
Posts: 48
That doesn't work either, neither the img or swf avatars show up so I'm assuming there is something wrong with the if statements
Joined: May 2000
Posts: 1,356
Addict
Addict
Joined: May 2000
Posts: 1,356
are you sure that $user_profile[20] is not blank and holds a jpg or gif or swf value? Also is $user_profile[20] correct slot? I dont know ubb member fields...
The above code seems right to me...
You can set a default valuve where it says 'my $this_img;'
my $this_img = '
';
Also, if it does not hold the full url, add it before $this_image;
$this_img = qq!
!;
etc...
Joined: May 2002
Posts: 48
Member
Member
Joined: May 2002
Posts: 48
$user_profile holds the correct URL...Im sure of this because when I use the code seperately without the if statements then the avatar shows up, its just when I add the if statements in nothing appears so Im assuming the if statements are wrong or theres something else wrong with the code ?
Joined: Aug 2000
Posts: 335
Member
Member
Joined: Aug 2000
Posts: 335
Try printing out $filename before the if's, and $this_img afterwards, to see what's going on. You could also simplify things a bit: if ($filename =~ m/.(gif|jpg)$/i) { ... } elsif ($filename =~ m/.swf$/i) { ... }
Joined: May 2002
Posts: 48
Member
Member
Joined: May 2002
Posts: 48
NM...trying now....was uploading the wrong file [EDIT]: Tried the simplied code and its still not working. How would I go about displaying the filename ? When I used $filename near where the images, rating is displayed I got a 0 as the output
Joined: Aug 2000
Posts: 335
Member
Member
Joined: Aug 2000
Posts: 335
Do you have access to your server error log? If so, you can output it there using 'warn': warn "filename='$filename'"; If not, you can output it to a temporary file: open(my $fh_debug, '>>', '/path/to/debug') or die "$!"; print $fh_debug scalar localtime, ":filename='$filename'n"; close($fh_debug);
Joined: Jan 2000
Posts: 5,073
Admin Emeritus
Admin Emeritus
Joined: Jan 2000
Posts: 5,073
... or you can just print "FN: $filename
";
UBB.classic: Love it or hate it, it was mine.
Joined: May 2002
Posts: 48
Member
Member
Joined: May 2002
Posts: 48
Got it to work !!!!!!!
Heres the code that I finally ended up using in case anybody else is interested
my $filename = chomp($user_profile[20]);
my $this_img;
if ($user_profile[20] =~ m/.(gif|jpg)$/i) {
$this_img = qq!
!;
}
elsif ($user_profile[20] =~ m/.swf$/i) {
$this_img = qq!
!;
}
Used User_profile[20] instead of $filename in the if statements and it ended up workiong..go figure... thanks for all the help
}
Joined: Sep 2002
Posts: 35
Member
Member
Joined: Sep 2002
Posts: 35
how is this to be used???
i'm looking to add an icon to indicate if an image is displayed within post??
Basically it will add an icon to a post if someone has posted an image within the topic. much like this forum does:
http://forums.vwvortex.com/zeroforum?id=27 could this code somehow work with that??
has anyone created such a hack that i mention??
Joined: May 2002
Posts: 48
Member
Member
Joined: May 2002
Posts: 48
Well this code is for getting external avatars to work...however I guess it could be used in the way you describe however it might require extensive modification
Joined: Mar 2001
Posts: 7,394
Admin / Code Breaker
Admin / Code Breaker
Joined: Mar 2001
Posts: 7,394
WC, I suggest you to use &ImageChecker($user_profile[20]), to make sure people don't do it for bad causes.
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Posts:
449
Joined: February 2008
Forums63
Topics37,575
Posts293,930
Members13,823
Most Online6,139Sep 21st, 2024
Currently Online
Topics Created
Posts Made
Users Online
Birthdays