PoiNtEr->: Web Interface For ADS Assignment

                             Difference between a dream and an aim. A dream requires soundless sleep, whereas an aim requires sleepless efforts.

Search This Blog

Saturday, September 8, 2012

Web Interface For ADS Assignment


Web Interface For ADS Assignment Supporting following languages
1:C
2:C++
3:Python
4:perl
5:ruby
6:java



Code Explanation:

  <img style="position:fixed; top:150px;"  src="einstein.jpg"></img>
<h3 style="position:fixed;top:110px;left:560px;right:50px"><center><b>Upload Input File:</b></center><br /></h3>


##upload Section##

<center><input  style="position:fixed; top:160px;left:750px;right:50px" type="file" name="inputfile[]" /><br /></center>
<br/>
<center><input  style="position:fixed; top:188px; left:870px;right:50px;" type="submit" value="Send" name="Send" action = "up.php" /></center>

  ###Action to upload Input file to server####



    <form name="form1" method="post" action="index2.php?saving=1">     

###INPUT TEXT AREA####

<textarea style="position:fixed; top:350px; width: 350px; height: 200px; left:920px;right:5px;" name="data" cols="90" rows="10">
</textarea>
<input style="position:fixed; top:560px; left:1100px;right:5px;"type="submit" value="Input">

</form>

  ####OUTPUT TExt Area#####
 

<textarea style="position:fixed; top:350px; width: 350px; height: 200px; left:500px;right:5px;name="output" cols="90" rows="10" >
    <?php $output = array();exec('./test2', $output); echo implode("\n", $output); ?>

</textarea>

#####./test2 is the name of your executable file ..it can be different depending on your choice of language or case ######




<br>

<input style="position:fixed; top:560px; left:600px;right:5px;"type="submit" value="Output">
</form>
    </p>

  ###########uploading file to the server...###############


<?php

if ($_REQUEST) {
    file_put_contents("InputFile.txt", $_REQUEST["text_box"]);
}
$name='Inputfile.txt';
if(isset($_POST['Send'])){
    foreach ($_FILES["inputfile"]["error"] as $key => $error) {
        if ($error == UPLOAD_ERR_OK) {
            $tmp_name = $_FILES["inputfile"]["tmp_name"][$key];
            $name = $_FILES["inputfile"]["name"][$key];
            move_uploaded_file($tmp_name, "data/$name");
            echo "File uploaded Successfully Uploaded...";
        }
    }
}


###You can try following options for fun ... which start with //#####
###exec is our magic php function  which we are using to call our executable from php#####

###implode is used to show output of our program as it is without any manipulation,otherwise exec only shows the last line of output###


//$output = array();
//exec('./ads12', $output);
//echo implode("\n", $output);

?> 
</body>
</html>

<style type="text/css">
body
{
background-color:#b0c4de;
}

 
</style>

 

######################################################################
index2.php
<?php
$saving = $_REQUEST['saving'];
if ($saving == 1){
$data = $_POST['data'];
$file = "Inputfile.txt";

$fp = fopen($file, "w+") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!");

fclose($fp);
echo "Saved to $file successfully!";
header( 'Location: http://eva.localhost/upload' ) ;


}
?>
########################################################################

Choice is yours either you can make a single php file with all this code or you can distribute load by making other index2.php and writing upload section in that.
Main thing is the  use of exec and implode function which gives us power to call any
function. If you have any problem in understanding code then feel free to leave comment below-->

No comments:

Post a Comment