vbscript in php

I am trying to check if a remote file exist on a windows share.  I know PHP does not support this on remote files but vbscript does.  There is a VBscript function using Scripting.FileSystemObject for this. But how do I use this in a php page?
mcsakeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
NetminderConnect With a Mentor Commented:
PAQed, with points refunded (75)

Netminder
EE Admin
0
 
carchitectCommented:
as you write javascript...similar manner
pls put your code here..


php supports this

As long as allow_url_fopen is enabled in php.ini, you can use HTTP and FTP URLs with most of the functions that take a filename as a parameter. In addition, URLs can be used with the include(), include_once(), require() and require_once() statements. See Appendix I for more information about the protocols supported by PHP.

Note: In PHP 4.0.3 and older, in order to use URL wrappers, you were required to configure PHP using the configure option --enable-url-fopen-wrapper.


Note: The Windows versions of PHP earlier than PHP 4.3 did not support remote file accessing for the following functions: include(), include_once(), require(), require_once(), and the imagecreatefromXXX functions in the Reference XLI, Image functions extension.


For example, you can use this to open a file on a remote web server, parse the output for the data you want, and then use that data in a database query, or simply to output it in a style matching the rest of your website.

Example 19-1. Getting the title of a remote page

<?php
$file = fopen ("http://www.example.com/", "r");
if (!$file) {
    echo "<p>Unable to open remote file.\n";
    exit;
}
while (!feof ($file)) {
    $line = fgets ($file, 1024);
    /* This only works if the title and its tags are on one line */
    if (eregi ("<title>(.*)</title>", $line, $out)) {
        $title = $out[1];
        break;
    }
}
fclose($file);
?>
 
 


You can also write to files on an FTP server (provided that you have connected as a user with the correct access rights). You can only create new files using this method; if you try to overwrite a file that already exists, the fopen() call will fail.

To connect as a user other than 'anonymous', you need to specify the username (and possibly password) within the URL, such as 'ftp://user:password@ftp.example.com/path/to/file'. (You can use the same sort of syntax to access files via HTTP when they require Basic authentication.)

Example 19-2. Storing data on a remote server

<?php
$file = fopen ("ftp://ftp.example.com/incoming/outputfile", "w");
if (!$file) {
    echo "<p>Unable to open remote file for writing.\n";
    exit;
}
/* Write the data here. */
fputs ($file, $_SERVER['HTTP_USER_AGENT'] . "\n");
fclose ($file);
?>
 
 



Note: You might get the idea from the example above that you can use this technique to write to a remote log file. Unfortunately that would not work because the fopen() call will fail if the remote file already exists. To do distributed logging like that, you should take a look at syslog().


0
 
mcsakeAuthor Commented:
The problem is that the file I want to check does not reside on a web server or a ftp server it is on a file server.

Here is a little bit of code to help explain what I am trying to do.

"if (file_exists($params)==FALSE)" does not work for remote files.  So basicly I need to replace this with vbscript or javascript that does.

Thanks


if (strchr($WrapParams,".ini"))
{
     $path = $server[0] . $WrapPath;
     $params = $server[0] . $WrapParams;

     //source on install server does not exist it looks for it on RPDRPDIV03
     if (file_exists($params)==FALSE)
     {
          $server[0] = "\\\\ARIES\\install$\\";
          $server[1] = "ARIES SERVER";
          $path = $server[0] . $WrapPath;
          $params = $server[0] . $WrapParams;
     }
}
else
{
     $path = $server[0] . $WrapParams;
     $params = "";
}

If (($Action == "Install") and ($info != ""))
{
     print "<center>Installing from Install server \"$server[1]\"<br></center>";
     ?>
     <SCRIPT LANGUAGE="VBScript">
     'oShell.MinimizeAll
     oShell.ShellExecute "<?echo $path?>", "<?echo $params?>", "", "open", "1"
     </SCRIPT>
     <?
}
0
 
GapingWoundCommented:
If the file server is on the same local network as the web server, AND the web server has a drive mapped to that share, you should be able to access it like it was a local file.

I do something similar to this at home with my mp3 server.
My mp3's are on a file server, and my mp3 software is on my local intranet server which has a mapped drive to the mp3 folder on the file server.
0
 
mcsakeAuthor Commented:
I figured it out

echo "<script language=\"VBScript\">\n";
echo "dim fso\n";
echo "Set fso = CreateObject(\"Scripting.FileSystemObject\")\n";
echo "if (fso.FileExists(\"$params\")) then \n";
echo "     MsgBox \"Launching $softwarename from $server[1]\"\n";
echo "     oShell.ShellExecute \"$path\", \"$params\", \"\", \"open\", \"1\"\n";
echo "else\n";    
echo "     MsgBox \"Launching $softwarename from $defaultserver\"\n";
echo "     oShell.ShellExecute \"$defaultpath\", \"$defaultparams\", \"\", \"open\", \"1\"\n";
echo "end if\n";
echo "</script>\n";
0
All Courses

From novice to tech pro — start learning today.