Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a PHP script from Perl

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I am using PHP GD lib to resize an image in an upload function.
The following code does the resize but I don't want the image displayed at this point.
Code:
print "<img border='0' src='[URL unfurl="true"]http://www.XXXXXXXXXX.co.uk/makethu.php?imnam=$JustFile&maxwid=250&maxhi=180&blow=17&norat=1'>";[/URL]

It should be possible to run the external file without returning anything but I am at a loss as to how it is done.

I thought of system, exec etc. but the syntax and method elude me.

I just need to run this command.
Code:
makethu.php?imnam=$JustFile&maxwid=250&maxhi=180&blow=17&norat=1



Keith
 
I think it depends very much on the implementation of makethu.php and whether it's capable of being run on a command-line, and what syntax it accepts its arguments in when run in that way. Did you write it yourself? Have you tried running it manually outside your script with any success?

This isn't really a perl question as such... system() is (one of) the obvious ways to run it, once you figure out the answer to those questions.

Annihilannic.
 
I am on a shared server, so I don't think I have access to the command line.
It is a very simple PHP script which makes a copy of an image and stores a resized version in another directory.
I did write it myself.
I have no idea what syntax it accepts it's arguements.
I thought it was a Perl question, where should I ask it?

Keith
 
That would make my life much easier but unfortunately, the GD module is not available on the server which this app is to be run on.
I thought there would be simple solution but it would appear to be more complex than I first thought.

On similar lines, how would I run a Perl script from within another?

Keith
 
Hi

audiopro said:
the GD module is not available on the server which this app is to be run on.
I would also check [tt]PerlMagick[/tt] too. Maybe...

audiopro said:
On similar lines, how would I run a Perl script from within another?
The problem is not about running. The problem is on the other side : to be run.

Your makethu.php can be called by the web server, so for an URL like this :

[tt]makethu.php?imnam=$JustFile&maxwid=250&maxhi=180&blow=17&norat=1[/tt]

So makethu.php receives from the PHP interpreter the following [tt]$_GET[/tt] :
Code:
Array
(
    [imnam] => $JustFile
    [maxwid] => 250
    [maxhi] => 180
    [blow] => 17
    [norat] => 1
)
But if you run it from the command line, you have to use a syntax like this :

[tt]makethu.php imnam=$JustFile maxwid=250 maxhi=180 blow=17 norat=1[/tt]

So makethu.php will receive from the PHP interpreter the following [tt]$argv[/tt] :
Code:
Array
(
    [0] => makethu.php
    [1] => imnam=$JustFile
    [2] => maxwid=250
    [3] => maxhi=180
    [4] => blow=17
    [5] => norat=1
)
You have to edit adapt your makethu.php script to handle the parameters received in the latter way.

Feherke.
 
I once wrote a web server in Perl that supported CGI scripts.

I did something along the lines of this, to run the CGI script:

Code:
# run the script...
{
  # set up a new %ENV environment for it
  local %ENV = (
    # populate the usual vars the CGI scripts might want
    QUERY_STRING => $query_str,
    REMOTE_ADDR  => $ip,
    HTTP_USER_AGENT => $client_header{'User-Agent'},
    # and so-on...
  };
  # now run it
  my $out = `perl /var/[URL unfurl="true"]www/$request`;[/URL]
  # send $out back to the client etc
}

Or basically, whatever's in Perl's %ENV hash, gets passed to any processes Perl runs as their environment variables.

Assuming the PHP interpreter uses an env variable named "QUERY_STRING" just like CGI does, PHP should automatically populate $_GET with all your query params.

Just a thought...

Kirsle.net | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
That got much more complex than I thought it would do.
The app is a simple picture upload which resizes the uploaded image. I have settled for displaying the uploaded image to save any further problems.

Thanks for you help any way.

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top