Need bytes (filesize) for podcast MP3 upload

6 posts by 3 authors in: Forums > CMS Builder
Last Post: August 18, 2011   (RSS)

By dwellingproductions - August 16, 2011 - edited: August 16, 2011

Hello!

We are creating an RSS file for an iTunes compatible podcast. It pulls info from CMS Builder inputted info for Title, Description, Upload, etc. Everything is working beautifully with one exception. (But, we know someone here will have the solution!) :-)

For each item, there is a necessary tag called "enclosure". One of its attributes is "length". This length attribute is needing a positive number indicating the total number of bytes that the uploaded MP3 file is.

I have tried accessing this with PHP's "filesize" function and CMS Builder's "urlPath" variable. But, that was resulting in a relative URL, when an absolute URL is required. So, I tried using the period to concatenate the missing domain root portion of the URL to the relative database stuff. Good idea, but does not work for some reason. (Though I was successful with this approach when supplying an absolute URL for the aforementioned "enclosure" tag's URL attribute.) And, I've tried using a variable with "filesize" which was a concatenation of the URL pieces, also with no success.

Unfortunately, using my very limited PHP knowledge, I have not been able to figure out a way to supply the number of bytes of the uploaded MP3 to this "length" attribute. Does anyone have any suggestions? (I hope...) :-)

Here's an example of what the output should look like:

<enclosure
url="http://www.mydomain.com/audio/uploads/file.mp3"
length="3336636"
type="audio/mpeg"
/>



Thanks, in advance, for any assistance.


Kindest regards,
Jeremy
---------------------------

Dwelling Productions

www.dwellingproductions.com

Re: [Dave] Need bytes (filesize) for podcast MP3 upload

Thank you Dave!!!!!

That works perfectly! (Much better than the mess I was making.) :-)

I really appreciate the assistance.

All the best!

- Jeremy
---------------------------

Dwelling Productions

www.dwellingproductions.com

Re: [Dave] Need bytes (filesize) for podcast MP3 upload

By Toledoh - August 18, 2011

Is there an easy way to change the display of this from bytes to kilobytes?
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Need bytes (filesize) for podcast MP3 upload

By Dave - August 18, 2011

Hi Tim,

We have a built in function that shows k, mb, etc.

Instead of this:
Size: <?php echo filesize($upload['filePath']) ?><br/>

Try this:
Size: <?php echo formatBytes( filesize($upload['filePath']), 0) ?><br/>

The second number is how many decimals to show.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Need bytes (filesize) for podcast MP3 upload

By Toledoh - August 18, 2011

Brilliant!
Cheers,

Tim (toledoh.com.au)