vbscript in php

Posted on 2003-03-13
Medium Priority
Last Modified: 2013-12-13
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?
Question by:mcsake
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8128287
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

$file = fopen ("http://www.example.com/", "r");
if (!$file) {
    echo "<p>Unable to open remote file.\n";
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];

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

$file = fopen ("ftp://ftp.example.com/incoming/outputfile", "w");
if (!$file) {
    echo "<p>Unable to open remote file for writing.\n";
/* 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().


Author Comment

ID: 8128441
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.


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;
     $path = $server[0] . $WrapParams;
     $params = "";

If (($Action == "Install") and ($info != ""))
     print "<center>Installing from Install server \"$server[1]\"<br></center>";
     oShell.ShellExecute "<?echo $path?>", "<?echo $params?>", "", "open", "1"

Expert Comment

ID: 8134454
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.

Author Comment

ID: 8184101
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";

Accepted Solution

Netminder earned 0 total points
ID: 11418340
PAQed, with points refunded (75)

EE Admin

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question