Page 1 of 2
Trying execute a file, is it possible?
Posted: Sun Nov 06, 2005 1:32 pm
by sheepz
Hello, I'm trying to write a website that checks the version of IE. My company needs all IE to be on 6.0 and above. If not we need to install IE6 for them. I tried to write a php site to do this. I want it to automatically start installing after the IF statement check. The file is downloaded from microsoft.com and is called "ie6setup.exe" This is stored in my "C:\Inetpub\wwwroot\ie6setup.exe" I keep getting a permission denied problem. I tried putting the ie6setup.exe to my desktop and still getting the same error. Here is the code
Code: Select all
<?
// Assign VAR $agent to display browser specifications
$agent=getenv("HTTP_USER_AGENT");
// Version check
if (preg_match("/MSIE 6/i", "$agent"))
{
$result="Your MS Internet Explorer is up to date.";
}
else
if (preg_match("/MSIE 5/i", "$agent"))
{
$result="Your Ms Internet Explorer needs to be updated... please wait while your IE updates...";
// filepath
$filename = "/Documents and Settings/Administrator/Desktop/ie6setup.exe";
$openfile = fopen($filename, "r+")
or die("Could not start upgrade please call IT Support for more information");
fclose($openfile);
}
else
{
$result="You are using $agent please call IT Support for more information";
}
?>
<html>
<head>
<title>Browser match results</title>
</head>
<body>
<?
// This will display the results to page
echo "<p>$result</p>";
?>
</body>
</html>
Here is the error msg I receive
Code: Select all
Warning: fopen(/Documents and Settings/Administrator/Desktop/ie6setup.exe) [function.fopen]: failed to open stream: Permission denied in c:\Inetpub\wwwroot\browsermatch.php on line 21
Could not start upgrade please call IT Support for more information
Posted: Sun Nov 06, 2005 1:34 pm
by Charles256
why not just offer a clickable link to download it if they're not using I.E. 6? just curious.
Posted: Sun Nov 06, 2005 1:43 pm
by sheepz
I would rather it automatically install because users would probably just close the webpage itself without installing the upgrade.
Posted: Sun Nov 06, 2005 1:52 pm
by m3mn0n
The proper path for that location needs to have
C:\ infront of it (or whatever is the proper drive letter).
And the method for delivery of the file is wrong. You do not want to open up the contents of the executable, you want to deliver them a link to the executable so they can install it so I recommend forwarding them to another page that starts the download automatically. And in that case it might be best to make the file available via the http protocol (ftp would be even better if available). Or sticking with the local file, use a snippet like so:
From a PHP manual comment:
Code: Select all
<?php
$downloadfile="somefile.txt";
header("Content-disposition: attachment; filename=$downloadfile");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".(string)(filesize($path)));
header("Pragma: no-cache");
header("Expires: 0");
?>
Posted: Mon Nov 07, 2005 1:39 am
by sheepz
I tried to use that snippet I must be missing something or a setting is wrong here is the code with extra installbrowser.php page
Code: Select all
<?
// Browsermatch.php
// Assign VAR $agent to display browser specifications
$agent=getenv("HTTP_USER_AGENT");
// Version check
if (preg_match("/MSIE 5/i", "$agent"))
{
header( "Location: /installbrowser.php");
exit;
}
else
if (preg_match("/MSIE 6/i", "$agent"))
{
$result="Your Ms Internet Explorer is up to date...";
}
else
{
$result="You are using $agent please call IT Support for more information";
}
?>
<html>
<head>
<title>Browser match results</title>
</head>
<body>
<?
// This will display the results to page
echo "<p>$result</p>";
?>
</body>
</html>
Here is the "instalbrowser.php"
Code: Select all
<?php
$downloadfile="ie6setup.exe";
header("Content-disposition: attachment; filename=$downloadfile");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".(string)(filesize($path)));
header("Pragma: no-cache");
header("Expires: 0");
?>
It opens a download window which gives me the choice of "open, save, or cancel" If i use open, it opens up a cmd window and stalls/crashes. If I choose save it saves to my desktop, then trying to execute the file it does the same thing opens a cmd window and stalls/crashes again.
I did notice the original file size is 500kb (in the wwwroot directory) and then after running the php and downloading it the file thru that, onto my desktop is 4.00kb way smaller and not the orginal size why is that?
I'm running IIS6 is there a setting I'm missing? It's setup to execute scripts and executables.
Posted: Mon Nov 07, 2005 1:56 am
by n00b Saibot
Code: Select all
<?php
$downloadfile="ie6setup.exe";
$path = "« put here path to .exe »";
header("Content-disposition: attachment; filename=$downloadfile");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".(string)(filesize($path.'/'.$downloadfile)));
header("Pragma: no-cache");
header("Expires: 0");
readfile($path.'/'.$downloadfile);
?>
Posted: Mon Nov 07, 2005 2:05 am
by sheepz
thx for the reply made those changes:
Code: Select all
<?php
$downloadfile="ie6setup.exe";
$path = "c:\inetpub\wwwroot";
header("Content-disposition: attachment; filename=$downloadfile");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".(string)(filesize($path.'/'.$downloadfile)));
header("Pragma: no-cache");
header("Expires: 0");
readfile($path.'/'.$downloadfile);
?>
but after clicking on "open" it just opens a cmd window and just stay theres. Nothing happens, looks like if its froze and I would have to click close to exit that cmd window.
Posted: Mon Nov 07, 2005 2:16 am
by n00b Saibot
remember to always use either double-backslash or forward slash while specifying path
should be either
or
Posted: Mon Nov 07, 2005 2:24 am
by sheepz
Thx for the correction. I made that changes, still having the same issue. I just want to chcek the version of IE and if it's 5 and below I would like the code to force a download. I already downloaded the updated version of IE 6 into the wwwroot directory. It's IE6Setup.exe, the code works because it gives me the option of "open, save, cancel" but both open and save doesn't seem to execute the file. Seems to open the command prompt window and just sits there. Do I need to check some settings on my IIS 6 ?
Posted: Mon Nov 07, 2005 2:31 am
by n00b Saibot
sheepz wrote:Seems to open the command prompt window and just sits there.

what has download to do with command prompt

and also you are not checking for IE 5 & less. you are only checking for IE 5....
Posted: Mon Nov 07, 2005 2:51 am
by sheepz
I'm sorry for the confusion. You are correct I'm only checking for IE 5. The code runs successfully, then does exec the file "ie6setup.exe" it also successfully gives me these options "open, save, cancel" when I click open to install ie6setup.exe the only thing happens is a command prompt window opens and nothing else. It just sits there, I don't want the cmd window to open I just want the executable ie6setup.exe to install. Unsure of why cmd window opens.
Posted: Mon Nov 07, 2005 3:11 am
by Chris Corbyn
sheepz wrote:I'm sorry for the confusion. You are correct I'm only checking for IE 5. The code runs successfully, then does exec the file "ie6setup.exe" it also successfully gives me these options "open, save, cancel" when I click open to install ie6setup.exe the only thing happens is a command prompt window opens and nothing else. It just sits there, I don't want the cmd window to open I just want the executable ie6setup.exe to install. Unsure of why cmd window opens.
Sounds like the data hasn't sent correctly and you have a corrupt exe file.
I'm still unsure if you're expeting an automatic install, or just a forced download dialog? You can't do the prior for security reasons... you can only ask the user to download and run the installer. make sure you have no whitespace, or anything that outputs to screen beofr eht <?php ?> tags since that will break your headers

Posted: Mon Nov 07, 2005 3:28 am
by sheepz
thx for the help =) I understand that the automatic install would be a security issue. The code does ask the user if I would like to download it (which is exactly what I want it to do). It runs the code and checks. When it finds that it is IE 5 it will procecced to the next page which is "installbrowser.php" so that is working also. But when executing that file, it just wont install. I tried using another .exe like "AIM5.exe" and still the same problem, after clicking on "open" it just opens a command prompt window and does not install. Should the file sit somewhere else beside "wwwroot" directory? I would like to send screen shots but it won't let me cut and paste in here
Posted: Mon Nov 07, 2005 3:54 am
by Chris Corbyn
sheepz wrote:thx for the help =) I understand that the automatic install would be a security issue. The code does ask the user if I would like to download it (which is exactly what I want it to do). It runs the code and checks. When it finds that it is IE 5 it will procecced to the next page which is "installbrowser.php" so that is working also. But when executing that file, it just wont install. I tried using another .exe like "AIM5.exe" and still the same problem, after clicking on "open" it just opens a command prompt window and does not install. Should the file sit somewhere else beside "wwwroot" directory? I would like to send screen shots but it won't let me cut and paste in here
I know exactly what you mean by the console window just opening and hanging.... it's a corrupt .exe file.
Try it yourself, create a text document then name it file.exe and open it.... same thing
It's most likely that your header() calls are not working due to whitespace or output before they are called.
Any more HTML/PHP above that code that you posted?
Posted: Mon Nov 07, 2005 4:05 am
by n00b Saibot
d11wtq wrote:I know exactly what you mean by the console window just opening and hanging.... it's a corrupt .exe file.
aww... It kinda dawned to me afterwards...
well sheepz, does the downloaded file still have 4KB size. then, you will have to correct your code as d11wtq said.
