/    Sign up×
Community /Pin to ProfileBookmark

Issue in Integrating Perl with PHP for Windows

Dear friends,

I am trying to Integrate the Perl (v5.8.6) code with PHP (5.3.0) for Windows.

Objective: I have developed a perl tool to validate a CD/DVD files and would like to present this tool to the user through our interanet webserver (PHP).
Issue: Perl couldn’t take the PHP argument as input!

Details:
I have placed the lnk.exe (perl tool) in localhost and triggering this exe through the below <?php?> code:

and i have passing the CD/DVD path as input argument to the Perl tool.

—PHP code—
<?php
if(isset($_POST[‘flcheck’])){
$path = $_
POST[‘filepath’];
$npath = substr($path, 0, (strlen ($path)) – (strlen (strrchr($path,’‘))));
echo “<br/>”;
echo “Removed file from path path — “.$npath;
echo “<br/>”;
$result = shell_exec(“lnk.exe $npath”);
echo ($result);
}
?>
<html>
<head>
<title>PHP with Perl</title>
</head>
<body>
<form name=”val” method=”post” onSubmit=””>
<table width=”100&#37;” border=”0″>
<tr>
<td width=”17%”>Browse the input path:</td>
<td width=”19%”><input name=”filepath” type=”file” class=”grid” id=”filepath” maxlength=”1000″ /></td>
<td width=”64%”><input name=”flcheck” type=”submit” class=”grid” id=”flcheck” value=”File check” /></td>
</tr>
</table>
</form>
</body>
</html>

I believe the lnk.exe has been triggered and the perl can not accepting the PHP argument as input. (refer the below output from perl&#8212;when am ran the lnk.exe manually its working fine)

—PHP output—
Removed file from path path — E:EBook+DevelopmentPearson_ebook_CDObservatoire_4e
Error in input argument: E:EBook+DevelopmentPearson_ebook_CDObservatoire_4e
Please try with correct input!

Any help appreciated!

Thanks in Advance,
Thirilog

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@themartySep 15.2010 — There are several things you need to improve:

1.
[code=php]if(isset($_POST['flcheck'])){[/code]

Some browser may not include this in the post variables if you don't actually click on the button (but submit the form by hitting enter

  • 2. You upload a file and try to access it with $_POST, which is not correct. You have to use the $_FILES superglobal and you should also include some checks to see if the upload succeeded. The manual has a lot of information on this:


  • http://php.net/manual/en/features.file-upload.php

    (also keep in mind you need to set the enctype attribute in your html form)

  • 3. Before executing the shell command you should check if the file exists.
  • Copy linkTweet thisAlerts:
    @ThirilogauthorSep 15.2010 — Thanks themarty! I'll try with your suggestions.

    Meanwhile i would like to rephrase my earlier post.
    -----


    I haven't tell few thing in detail above sorry!

    I am using php to trigger the perl file with input of CD/DVD package path as argument, and haven't upload any files to host for execution.

    Am facing issue in getting input argument from php.

    To ease the testing here am give the sample codes please help...

    ---Perl code---

    $filepath = $ARGV[0];

    print "Perl triggered and receiving $filepath path as argument!<br/>";

    if (not(-d $filepath)){

    print "nError in input argument: $filepath<br/>Please try with correct input!<br/><br/>";

    die();

    }

    else {

    print "Perl could process with the received $filepath argument<br/>";

    }

    ---PHP code---

    <?php

    if(isset($_POST['flcheck'])){

    $path = $_
    POST['filepath'];

    $npath = substr($path, 0, (strlen ($path)) - (strlen (strrchr($path,''))));

    echo "<br/>";

    echo "After trimmed the path -- ".$npath;

    echo "<br/>";

    $result = shell_exec("test.pl $npath");

    echo ($result);

    }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>PHP with Perl</title>

    <style>

    body,html{

    margin:20; padding:0;

    background-color:#f7f7f7;

    overflow:auto;

    }

    label{

    font-family: Verdana, Arial, Helvetica, sans-serif;

    font-size: 12px;

    font-weight: bold;

    color: #FF6633;

    text-decoration: none;

    padding-right: 8px;

    padding-left: 5px;

    margin-left:107px;

    margin-top:20px;

    }

    table.grid { background:#B0C4DE; border-bottom:#5496CA solid 2px; font-size:11px; font-family:Verdana, Arial, Helvetica, sans-serif; }

    table.grid input { font-size:11px; font-family:Verdana, Arial, Helvetica, sans-serif; }

    table.grid tr { font-size:15px; font-size:large; font-family:Verdana, Arial, Helvetica, sans-serif; }

    td { font-size:10px; font-size:small; font-family:Verdana, Arial, Helvetica, sans-serif; }

    </style>

    </head>

    <body>

    <form name="val" method="post" onSubmit="">

    <table width="100&#37;" border="0">

    <tr>

    <td width="17%">Browse the input path:</td>

    <td width="19%"><input name="filepath" type="file" class="grid" id="filepath" maxlength="1000" /></td>

    <td width="64%"><input name="flcheck" type="submit" class="grid" id="flcheck" value="File check" /></td>

    </tr>

    </table>

    </form>

    </body>

    </html>


    ---Output---

    After trimmed the path -- myPearsoneBook.exe

    Perl triggered and receiving myPearsoneBook.exe path as argument!

    Error in input argument: myPearsoneBook.exe

    Please try with correct input!


    Thanks in Advance,

    Thirilog
    Copy linkTweet thisAlerts:
    @themartySep 15.2010 — if you're not trying to upload a file then you should make your input field just a regular text-type and not file-type.

    still, before you execute the shell command you should verify (in PHP) that the file(path) exists. If you have done that and the file exists then you should echo the full command to your screen and try it directly at the prompt.
    ×

    Success!

    Help @Thirilog spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...