Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Error in accessing remote file. Please help.

    Hi,
    I'm using the below code for accessing a remote file.

    Code:
    $filelocation = "\\fs-blr-03\str_audio1\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt";
    $fp = fsockopen($filelocation, 80, $errno, $errstr, 30);
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: ".$filelocation."\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        $result .= fgets($fp, 128);
    }
    fclose($fp);
    print $result;
    But it giving the following error:

    Code:
    Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Program Files\Apache Group\Apache2\htdocs\selected_stream.php on line 75
    
    Warning: fsockopen() [function.fsockopen]: unable to connect to \\fs-blr-03\str_audio1\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt:80 (Unknown error) in C:\Program Files\Apache Group\Apache2\htdocs\selected_stream.php on line 75
    Please help.

    Thanks,
    Ramki.

  • #2
    New Coder
    Join Date
    Feb 2008
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi

    Nowhere in your code do you tell fsockopen what the address of the server is.

    You code needs to look something like this:

    PHP Code:
    $remoteServerAddress 'www.yourserver.com';
    $filelocation "\\fs-blr-03\str_audio1\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt";
    $fp fsockopen($remoteServerAddress80$errno$errstr30);
    $out "GET $filelocation HTTP/1.1\r\n";
    $out .= "Host: ".$remoteServerAddress."\r\n";
    $out .= "Connection: Close\r\n\r\n"
    Another problem is that you are using backslashes

    fs-blr-03\str_audio1\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt

    should be fs-blr-03/str_audio1/Automation/Data_files/playback_automation_datafile_WMA_48kHz_full.txt

  • #3
    New Coder
    Join Date
    Feb 2008
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Wait? Are you trying to access a network share?

    If that is the case it is better to map a drive locally and read the file as if that file was on the machine's harddrive itself.

    ie map z: to \\fs-blr-03\str_audio1 (if on a windows machine)

    Then read the file like you would any other file

    PHP Code:
    $filename "z:\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt";
    $handle fopen($filename"r");
    $contents fread($handlefilesize($filename));
    fclose($handle); 
    Last edited by deamonlizard; 02-20-2008 at 09:40 AM.

  • #4
    New Coder
    Join Date
    Oct 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts
    yes... its on the network share. Even after mapping i'm getting the following error,


    Code:
    Warning: fopen(x:\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt) [function.fopen]: failed to open stream: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\selected_stream.php on line 92
    
    Warning: filesize() [function.filesize]: stat failed for x:\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt in C:\Program Files\Apache Group\Apache2\htdocs\selected_stream.php on line 93
    But when the same file is copied on to my local machine the your code works! I'm not able to figure out whats the problem!!!

    Thanks,
    Ramki.
    Last edited by ramki067; 02-20-2008 at 09:58 AM.

  • #5
    New Coder
    Join Date
    Feb 2008
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Then your box cannot see the file

    Do this

    Click Start
    Click Run
    x:\Automation\Data_files\

    A new explorer window will open - if not the share isn't set up correctly. If that is the case just type "x:\" in the Run box and check what is going on

    If it opens rightclick that playback_automation... file and select rename - but don't type anything

    Copy the file name.

    Paste the name of that file into php

    That way you ensure that you didn't make any typing mistakes. Always cut and paste long names (whether it is a long file name or a long database field - it just helps you avoid those silly typing mistakes that can sometimes take ages to debug)

    Let me know if it worked

  • #6
    New Coder
    Join Date
    Oct 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I did what u said. But when i typed x: in run, a window opened directly to fs-blr-03\str_audio1 folder from their i was able to go the particular file and open it.

    I copied and pasted the complete path from their and still i'm getting the below error!

    Code:
    Warning: fopen(X:\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt) [function.fopen]: failed to open stream: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\selected_stream.php on line 93
    File cannot be opened!

    My code is as below:

    Code:
    $filename = "X:\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt";
    $handle = fopen($filename, "r");
    
    if(!$handle){
      echo "File cannot be opened!";
      //	exit;
    }
    
    else{
    $contents = fread($handle, filesize($filename));
    print $contents;
    
    }
    fclose($handle);
    But when the same file is copied on to my local machine the your code works! I'm not able to figure out whats the problem!!!


    Thanks,
    RAmki.

  • #7
    New Coder
    Join Date
    Feb 2008
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    OK, next test

    Click Start->Run

    Paste the entire file string into run, exactly like this

    X:\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt

    Notepad should immediately open the file. If not just type X: in the Run box and make 100% sure that the directory is called Automation and that the next directory is called Data_files

  • #8
    New Coder
    Join Date
    Oct 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts
    done and the path you mentioned is perfectly working as its opening the file in wordpad.

    I'm using the local file temporarily. can you please help me on how to find the tab space in file contents? I need to extract the contents from just after first tab space to the second tab space.

    Thanks,
    Ramki.
    Last edited by ramki067; 02-20-2008 at 10:21 AM.

  • #9
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Hi,

    Firstly, extracting data between first two tab spaces:

    PHP Code:
    preg_match("/\t([\S| ]+)\t/",  //Regexp pattern.
               
    $string,           //String containing the data.
               
    $matches);         //The match will be put into $matches. 
    Secondly, what is the result of calling stat() on the remote file?

  • #10
    New Coder
    Join Date
    Oct 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks for the reply mlse.

    I added your code to my code as below:

    Code:
    $filename ="C:\Program Files\Apache Group\Apache2\htdocs\playback_automation_datafile_WMA_48kHz_full.txt";
    $handle = fopen($filename, "r");
    
    
    if(!$handle){
      echo "File cannot be opened!";
      //	exit;
    }
    
    else{
    
    while(!feof($handle)){
      $contents = fread($handle, 1024);
      preg_match("/\t([\S| ]+)\t/",$handle,$matches);
      echo " $matches <br>";
    }
    }
    fclose($handle);

    and i'm getting a series of :

    Warning: preg_match() expects parameter 2 to be string, resource given in C:\Program Files\Apache Group\Apache2\htdocs\selected_stream.php on line 105

    What is this behaviour? What does it signifies?

    Thanks,
    RAmki.

  • #11
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    preg_match works on strings, not resources: http://uk3.php.net/manual/en/function.preg-match.php (hint - look at what you are actually passing in as the second parameter of preg_match).

  • #12
    New Coder
    Join Date
    Oct 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks.. can u please answer my other thread thus posted.

    Ramki.

  • #13
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Ok, what is the result of calling stat() on the remote file?

  • #14
    New Coder
    Join Date
    Oct 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlse View Post
    Ok, what is the result of calling stat() on the remote file?
    How do i use this? I've used it as below,

    Code:
    $filelocation = "\\\fs-blr-03\str_audio1\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt";
    print_r(stat($filelocation));
    
    $fp = fopen($filelocation,'r');
    
    if(!($fp)){
      echo "<b>Cannot access file,$array[0]</b><br>";
    }
    
    else{
    $lines = file($fp);
    $i=0;
    foreach($lines as $line_num => $line)
    {
    preg_match('/\t([-\w]+)[^\t]*\t([-\w]+)/', $line, $matches);
    echo "$matches[1]<br />\n"; 
    }
    }
    but getting error as below:


    Code:
    Warning: stat() [function.stat]: stat failed for \\fs-blr-03\str_audio1\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt in C:\Program Files\Apache Group\Apache2\htdocs\selected_stream.php on line 116
    Warning: fopen(\\fs-blr-03\str_audio1\Automation\Data_files\playback_automation_datafile_WMA_48kHz_full.txt) [function.fopen]: failed to open stream: Permission denied in C:\Program Files\Apache Group\Apache2\htdocs\selected_stream.php on line 116
    
    Notice: Undefined variable: filename in C:\Program Files\Apache Group\Apache2\htdocs\selected_stream.php on line 119
    Cannot access file,
    Last edited by ramki067; 02-21-2008 at 05:28 AM.

  • #15
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Ok, try the same thing with the locally mapped path to the shared file, what happens then?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •