By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,615 Members | 1,634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,615 IT Pros & Developers. It's quick & easy.

Coverting perl to php

P: n/a
Hi

I have some perl code that lets me request different things, images,
audio, etc and it will output the correct mime type header and
"stream" the file to a browser (instead of a hard link to the image
itself). I am bout ready to convert it to php but wonder if there are
already built in commands to do this. If so can someone give me a
pointer or 2 where to look in the manual (I am not that good with
search engines).

TYI

Bill H
Sep 3 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 3 Sep, 20:25, Bill H <b...@ts1000.uswrote:
Hi

I have some perl code that lets me request different things, images,
audio, etc and it will output the correct mime type header and
"stream" the file to a browser (instead of a hard link to the image
itself). I am bout ready to convert it to php but wonder if there are
already built in commands to do this. If so can someone give me a
pointer or 2 where to look in the manual (I am not that good with
search engines).

TYI

Bill H
<?php

$src="/path/to/some_file.mp3";

if (file_exists($src)) {
header('Content-type: audio/mpeg');
readfile($src);
} else {
header('HTTP/1.0 404 Not Found');
print "Whoops!\n";
}

?>

Note that the above is not actually streaming - just writing the file
to the browser. Have a google for progresive download for how to
emulate streaming across HTTP.

As for determining mime-type for a arbitary file - it depends on your
OS and webserver - but most have a mime-types file which maps file
extensions to mime types. Or, if you're running on a Unix/Linux system
you can call the 'file' command from PHP to get the mime-type (see man
file for more info).

C.
Sep 4 '08 #2

P: n/a
<snip>
>
@OP: Why are you rewriting in PHP? If it works in Perl, and if it's what
you know, rewriting to PHP would be inefficient, and counter-intuitive.
Pretty much all hosting companies should have Perl available.
Yes, they do.

But I was losing work, with perl. And I think that little development
is going on in perl.

I have a series of utilities (a perl module that I'm writing as a php
class) that do the normal sorts of stuff and since all new code is in
php, I need the utility to match. I'm not rewriting existing apps.

Gives me the chance to improve on what I had done. I had a friend
that said that you should throw out the first two code versions!

I much prefer the php class idea over the perl module.

Jeff
>
--
Curtis
Sep 4 '08 #3

P: n/a
Jeff wrote:
<snip>
>>
@OP: Why are you rewriting in PHP? If it works in Perl, and if it's
what you know, rewriting to PHP would be inefficient, and
counter-intuitive. Pretty much all hosting companies should have Perl
available.

Yes, they do.

But I was losing work, with perl. And I think that little development
is going on in perl.
I see, that's unfortunate. However, the Perl community is very much
alive, and many new things are on the way for Perl 6; so it is
definitely still under active development.
I have a series of utilities (a perl module that I'm writing as a php
class) that do the normal sorts of stuff and since all new code is in
php, I need the utility to match. I'm not rewriting existing apps.

Gives me the chance to improve on what I had done. I had a friend that
said that you should throw out the first two code versions!

I much prefer the php class idea over the perl module.
Fair enough. :-)

--
Curtis
Sep 5 '08 #4

P: n/a
Curtis wrote:
Jeff wrote:
><snip>
>>>
@OP: Why are you rewriting in PHP? If it works in Perl, and if it's
what you know, rewriting to PHP would be inefficient, and
counter-intuitive. Pretty much all hosting companies should have Perl
available.

Yes, they do.

But I was losing work, with perl. And I think that little
development is going on in perl.

I see, that's unfortunate.
I thought so. I thought I held out too long. Far too long.

However, the Perl community is very much
alive, and many new things are on the way for Perl 6; so it is
definitely still under active development.
No kidding! I really thought that was a never going to happen. Is it
going to be written in C++ instead of C?

OK, I just googled, and I saw nothing post 2005 :-(

I've always liked the brevity of perl. It's written for speed (in
programming) and as they say, more than one way to do it. I never found
anything I couldn't do that I wanted to do. And DBI rocks!
>
> I have a series of utilities (a perl module that I'm writing as a
php class) that do the normal sorts of stuff and since all new code is
in php, I need the utility to match. I'm not rewriting existing apps.

Gives me the chance to improve on what I had done. I had a friend
that said that you should throw out the first two code versions!

I much prefer the php class idea over the perl module.

Fair enough. :-)
The only thing I can say now is that I'm glad I never learned php4
specific stuff! Now if php6 would just toss in some of my favorite perl
bits...

Jeff
>
--
Curtis
Sep 5 '08 #5

P: n/a
Jeff wrote:
Curtis wrote:
>Jeff wrote:
>><snip>

@OP: Why are you rewriting in PHP? If it works in Perl, and if it's
what you know, rewriting to PHP would be inefficient, and
counter-intuitive. Pretty much all hosting companies should have
Perl available.

Yes, they do.

But I was losing work, with perl. And I think that little
development is going on in perl.

I see, that's unfortunate.

I thought so. I thought I held out too long. Far too long.

However, the Perl community is very much
>alive, and many new things are on the way for Perl 6; so it is
definitely still under active development.

No kidding! I really thought that was a never going to happen. Is it
going to be written in C++ instead of C?

OK, I just googled, and I saw nothing post 2005 :-(
Perl 6 has been under development for almost 10 years, apparently. A
brief Google search turned up this FAQ about Perl 6:

<URL:http://dev.perl.org/perl6/faq.html>

As for the community, if you try perlmonks or other such places, I
would imagine them quite active. I'm not really active in the Perl
community, so I can't say for sure.

Perl 5 is very stable, so changes are quite rare and minimal.
I've always liked the brevity of perl. It's written for speed (in
programming) and as they say, more than one way to do it. I never found
anything I couldn't do that I wanted to do. And DBI rocks!
>>
>> I have a series of utilities (a perl module that I'm writing as a
php class) that do the normal sorts of stuff and since all new code
is in php, I need the utility to match. I'm not rewriting existing apps.

Gives me the chance to improve on what I had done. I had a friend
that said that you should throw out the first two code versions!

I much prefer the php class idea over the perl module.

Fair enough. :-)

The only thing I can say now is that I'm glad I never learned php4
specific stuff! Now if php6 would just toss in some of my favorite perl
bits...

Jeff
The last I read of PHP 6 features was from a meeting between the devs
in 2005, although you can download snaps of the current state of PHP 6
right now.

--
Curtis
Sep 7 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.