# PHP question - grabbing a file with a lower case extension...

**URL:** <https://boards.straightdope.com/t/php-question-grabbing-a-file-with-a-lower-case-extension/398337>\
**Category:** Factual Questions\
**Created:** [April 1, 2007, 11:11pm UTC](https://boards.straightdope.com/t/php-question-grabbing-a-file-with-a-lower-case-extension/398337 "2007-04-01T23:11:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaelghat](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@aaelghat](https://boards.straightdope.com/u/aaelghat)\
**Post date:** [April 1, 2007, 11:11pm UTC](https://boards.straightdope.com/t/php-question-grabbing-a-file-with-a-lower-case-extension/398337/1 "2007-04-01T23:11:43Z")

</div>

Hi, I realize this may not be the best message board for this question, so if you know of a better one please let me know…

Here’s my problem - I’m trying to grab a .wav file and make an MP3 out of it using the program sox. However, the directory which has the .wav files also has .WAV files. A .WAV file is MS wav format, gsm encoded (wav49) and is encoded differently than .wav file which is MS wav format, 16 bit linear.

Anyway, what I want to grab is the .wav file and it’s grabbing the WAV file. The code is below. I tried changing the second line to

$wav = $fl[0].”.WAV”;

but that didn’t do it. I don’t really know PHP - I’m just modifying someone else’s code. Does anyone know what I need to do to grab the right file or a different message board where I should post my question? Thanks.

function getMP3File($d, $file, $props, $device, $mailbox, $vm\_config, $vm\_name, $context) {

$fl = split(“.”,$file);  
$wav = $fl[0].“.wav”;  
$uid = $fl[0].“.”.sha1($props[‘origtime’]. $props[‘callerchan’].$props[‘duration’]);  
$mp3 = $uid.‘.mp3’;

if (!file\_exists($d . $mp3)) {//generate mp3 file if it doesn’t exist  
$cid = getCallerIDArray($props[‘callerid’]);  
$title = ’ --tt “Message from ‘. $cid[0]. ’ ph# ’ . $cid[1] .’”‘;  
$artist = ’ --ta "’. $cid[0].‘"’;  
$album = ’ --tl “'. $vm\_config[$context][$device][1] . ‘'s mailbox ’ . $mailbox .’ at ’ . $vm\_name . '”‘;  
$comment = ’ --tc “Generated by LifeOnRecord Feeder [http://www.LifeOnRecord.com](http://www.LifeOnRecord.com)”’;  
system(‘/usr/bin/lame -h --nspsytune --athtype 2 --lowpass 11 --ns-bass -8 --scale 0.93 --cbr -b 96 --resample 22.05 --add-id3v2’ . $title . $artist . $album . $comment . ’ ’ . $d . $wav . ’ ’ . $d . $mp3 .’ &');  
}  
return $uid;  
}

---

<div class="post-metadata">

**Author:** ![aaelghat](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@aaelghat](https://boards.straightdope.com/u/aaelghat)\
**Post date:** [April 1, 2007, 11:21pm UTC](https://boards.straightdope.com/t/php-question-grabbing-a-file-with-a-lower-case-extension/398337/2 "2007-04-01T23:21:24Z")

</div>

One piece of information I should have mentioned is that the PHP code is running on a Linux server.

---

<div class="post-metadata">

**Author:** ![ZipperJJ](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zipperjj/32/211_2.png) [@ZipperJJ](https://boards.straightdope.com/u/ZipperJJ)\
**Post date:** [April 2, 2007, 12:17am UTC](https://boards.straightdope.com/t/php-question-grabbing-a-file-with-a-lower-case-extension/398337/3 "2007-04-02T00:17:55Z")

</div>

I’m no PHP expert but if I was doing this in ASP I would make sure the strings always match by making the requested string and the matching string uppercase. Looks like you need to use [str\_to\_upper](http://us2.php.net/strtoupper).

So…WAV would always match str\_to\_upper($str) no matter if it’s stored on the server as WAV or wav.

Someone else with more skillz might come along and give you specific help for your func, but you can chew on that for a while.

---

<div class="post-metadata">

**Author:** ![ZipperJJ](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zipperjj/32/211_2.png) [@ZipperJJ](https://boards.straightdope.com/u/ZipperJJ)\
**Post date:** [April 2, 2007, 1:35am UTC](https://boards.straightdope.com/t/php-question-grabbing-a-file-with-a-lower-case-extension/398337/4 "2007-04-02T01:35:32Z")

</div>

Yeah my bad…it’s strtoupper() not str\_to\_upper.

Carry on.

---

<div class="post-metadata">

**Author:** ![aaelghat](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@aaelghat](https://boards.straightdope.com/u/aaelghat)\
**Post date:** [April 2, 2007, 1:44am UTC](https://boards.straightdope.com/t/php-question-grabbing-a-file-with-a-lower-case-extension/398337/5 "2007-04-02T01:44:38Z")

</div>

Thanks Zipper. I’m confused as to how that would help me…

In the directory the script is reading there are files like this:

msg0014.WAV  
msg0014.wav  
msg0013.WAV  
msg0013.wav

If I always want to grab the .WAV files, and I use strtoupper() then won’t the .wav files look like WAV files and and I won’t be able to differentiate anymore? Or am I missing something? I guess the problem is that the files have the same name except for the case, and I always want to grab the file with the upper case extension.

Thanks.
