Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old September 3rd, 2008, 08:35 PM
Bill H
Guest
 
Posts: n/a
Default Coverting perl to php

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
  #2  
Old September 4th, 2008, 01:25 PM
C. (http://symcbean.blogspot.com/)
Guest
 
Posts: n/a
Default Re: Coverting perl to php

On 3 Sep, 20:25, Bill H <b...@ts1000.uswrote:
Quote:
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.
  #3  
Old September 4th, 2008, 03:55 PM
Jeff
Guest
 
Posts: n/a
Default Re: Coverting perl to php

<snip>
Quote:
>
@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
Quote:
>
--
Curtis
  #4  
Old September 5th, 2008, 01:55 AM
Curtis
Guest
 
Posts: n/a
Default Re: Coverting perl to php

Jeff wrote:
Quote:
<snip>
Quote:
>>
>@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.
Quote:
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
  #5  
Old September 5th, 2008, 11:25 PM
Jeff
Guest
 
Posts: n/a
Default Re: Coverting perl to php

Curtis wrote:
Quote:
Jeff wrote:
Quote:
><snip>
Quote:
>>>
>>@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
Quote:
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!
Quote:
>
Quote:
> 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
Quote:
>
--
Curtis
  #6  
Old September 7th, 2008, 09:45 AM
Curtis
Guest
 
Posts: n/a
Default Re: Coverting perl to php

Jeff wrote:
Quote:
Curtis wrote:
Quote:
>Jeff wrote:
Quote:
>><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
Quote:
>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.
Quote:
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!
Quote:
>>
Quote:
>> 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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles