PHP Classes

Failed to open stream

Recommend this page to a friend!

      MS-Excel Stream Handler  >  All threads  >  Failed to open stream  >  (Un) Subscribe thread alerts  
Subject:Failed to open stream
Summary:failed to open stream
Messages:10
Author:dak
Date:2005-12-28 07:49:13
Update:2009-04-02 16:05:38
 

  1. Failed to open stream   Reply   Report abuse  
Picture of dak dak - 2005-12-28 07:49:13
Hi,

I really hope someone can help me. I'm new to writing PHP scripts. I've been trying to use this class for the last 4 hours but couldn't get it to work. I've downloaded the excel.php, download & export examples into one folder. I've also created a file example.xls in the same folder as well as in another folder called tmp. By the way, I'm using Maguma Studio 1.3.3 and xampp.

I tried running both the download & export examples but got the following errors:

PHP Warning: readfile(xlsfile://tmp/example.xls): failed to open stream: "xlsstream::stream_open" call failed in C:\Documents and Settings\-\My Documents\readexcel2\~scp.php on line 18

Cannot open xlsfile://tmp/example.xlsPHP Warning: fopen(xlsfile://tmp/example.xls): failed to open stream: "xlsstream::stream_open" call failed in C:\Documents and Settings\-\My Documents\readexcel2\~scp.php on line 11

Really hope someone can help me...thanks

  2. Re: Failed to open stream   Reply   Report abuse  
Picture of Phil Phil - 2005-12-30 17:24:10 - In reply to message 1 from dak
The reason is... You're trying to write/read a unix compliant directory, not win32.

xlsfile://tmp/example.xls "/tmp/example.xls" isn't a valid windows path, You need to use, for example... C:/example.xls

  3. Re: Failed to open stream   Reply   Report abuse  
Picture of João João - 2006-01-02 12:46:13 - In reply to message 1 from dak
My post "is not" for solving your problem!

But if you want to create a complicated excel file see
“Alternative MS-Excel Classes
If you're looking for an Excel class to do more...”
thread in this forum.

I’m using the PEAR package and I’m very happy because handling information is much easier. The installation of PEAR and package is simple too!

  4. Re: Failed to open stream   Reply   Report abuse  
Picture of R S R S - 2006-07-27 17:39:23 - In reply to message 1 from dak
This is probably 7 months too late, but for anyone else who is experiencing this problem (as I just was), the problem is in the stream_open() function. The first thing it does is parse $path as a url then it does this:
$this->xlsfilename = '/' . $url['host'] . $url['path'];
presuming that the specified file path is an absolute path, hence the prepending of the root ('/') to the filename. Simply remove the "'/' ." so the line is:
$this->xlsfilename = $url['host'] . $url['path'];
And this will allow users to open files as relative or absolute paths. E.g.,
readfile('xlsfile://./example.xls');
or
readfile('xlsfile://c:/foo/bar.xls');

Obviously, this is all only for Windows systems.

  5. Re: Failed to open stream   Reply   Report abuse  
Picture of onur keskin onur keskin - 2006-09-08 07:03:45 - In reply to message 4 from R S
the class doesn't recognize "./". If you give the path as "xlsfile://./file.xls", it creates a file at the root path(for ex. "c:\file.xls").

  6. Re: Failed to open stream   Reply   Report abuse  
Picture of S.M. Mehedi Hasan S.M. Mehedi Hasan - 2007-12-14 11:18:45 - In reply to message 4 from R S
Thanks. My problem is solved using ur technique.

  7. Re: Failed to open stream   Reply   Report abuse  
Picture of govanthan govanthan - 2008-05-20 07:06:09 - In reply to message 6 from S.M. Mehedi Hasan
Can u send me ur code as sample

  8. Re: Failed to open stream   Reply   Report abuse  
Picture of Gervasio Marchand Gervasio Marchand - 2008-08-21 19:21:53 - In reply to message 1 from dak
Yep, removing '/' worked here too :D thanks!

  9. Re: Failed to open stream   Reply   Report abuse  
Picture of kyungjoon min kyungjoon min - 2008-08-29 16:27:29 - In reply to message 7 from govanthan
Try removing the @ in the following code in the function stream_open.
$this->fp = @fopen($this->xlsfilename, $this->mode);

This will give more exact error code.

If you code like below in window 2003 server,

$fp = fopen('xlsfile://./temp/bar.xls',"wb");

it will open the file bar.xls in C:\temp directory.

  10. Re: Failed to open stream   Reply   Report abuse  
Picture of Tyler Clemens Tyler Clemens - 2009-04-02 16:05:38 - In reply to message 9 from kyungjoon min
After 2 days of going over this excel.php file I finally found out what is causing this problem. It has to do with the way the php fucntion PARSE_URL works.

For a better understanding of how this function works, refer to the following URL:
us3.php.net/parse_url

$url = 'http://username:password@hostname/path?arg=value#anchor';
$myParsedArray = parse_url($url);

In short, that will return this array:
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)

So in excel.php in the stream_open function, at line 74:
$this->xlsfilename = $url['host'] . $url['path'];
If for instance you passed it:
"xlsfile://C:/example.xls"

xlsfilename = C/example.xls

Notice the missing : after C

To fix this problem, change line 74 to:
$this->xlsfilename = $url['host'] . ":" . $url['path'];