Hello,

I am creating an upload material program for elearning. Now, I have an exe file, if I run it from my computer it's directly open a new browser and run it's content. Now, if I click the material list in my web browser, it's asking me to save the file instead of directly opening the files.

I would like to directly open the files (only for *.exe file), how to create the program like that?

This is the code that I have so far.

add_material.php

<?php 
                //LOAD MATERIAL TABLE

                $result = mysql_query("SELECT * FROM material WHERE material.class_name='".$_GET['class_name']."'") or die(mysql_error());
                ?>


                <table id="admintable" border="0" cellpadding="2" cellspacing="0">
                    <tr style="border:0;"><td style="border:0;"><?php echo "Class Name: ".$_GET['class_name']; ?><br><br></td></tr>
                    <tr>             
                        <th>material</th><th>Post</th>
                    </tr>
                    <?php
                    $i=0;
                    while ($data = mysql_fetch_array($result)){
                    $result2=($i%2)?'#DFA09D':'white';


                            echo "<tr bgcolor='$result2'>";                      
                            echo '<td><a href="materialstorage/'.$data['material'].'">'.$data['material'].'</a></td>';                          
                            echo '<td style="width: 50px"><a href="add_material.php?class_name='.$data['class_name'].'&material_id='.$data['material_id'].'">Delete</a></td>';
                            echo '</tr>';

                    $i++;   
                    }
                    ?>
                </table>

I would like to directly open the files (only for *.exe file), how to create the program like that?

You cannot. This is blocked by the browser.

the only work around for this is to compile the .exe in the OS running the server e.g. linux, ubuntu, and others.

for example, you have an executable application called app_x.exe, you need to compile it from the source inside your server's OS.

Once it is installed, you reference the location e.g. usr/local/bin or usr/bin/local/app_x

The PHP code for it will be something like this

exec("app_x ## put other stuffs here e.g. input  2>&1" , $output_from_program);

foreach($output_from_program as $item){

    echo $item .'<br/>';

    }

It will be difficult and tedious, but not impossible to do this on Apache2 on windows. On windows, you can compile by using MingGW.

Member Avatar for iamthwee

This is a bad idea, most exes tend to be os reliant. Not everyone is going to be using windows as their OS.

@iamthwee,

You are correct. If he is going to distribute this application, no one will be willing to accept a win32 dll file just to run this application. Unless, he can manage to compile the exe just for the PHP. However, executables are not extensions where dll files can be added in the php ext directory. It needs at least 1 for the OS and 1 for the PHP extension for it to work. But then, it looks like he is building something for school or on online classroom. So, he should be able to do it on his own server.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.