TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-22-2008, 04:52 AM   #1 (permalink)
The Wanderer
 
superthin's Avatar
 
Join Date: Aug 2008
Posts: 16
Thanks: 7
superthin is on a distinguished road
Default Where is my file?

Hi every body,

I am creating a small project to manage some books for my team. Exporting database to an Excel (*.xls) file is very important because an the team's member will use that file to import into an barcode printing application.

I found Class: MS-Excel Stream Handler (excel, xls, spreadsheet, read excel) - PHP Classes . This class is useful. I could get an Excel file like I expected (through download, cannot find file on server).

The problem was I cannot understand:

Code:
// line 9 to 15 in example_export.php from the class above

require_once "excel.php";
$export_file = "xlsfile://tmp/example.xls";
$fp = fopen($export_file, "wb");
if (!is_resource($fp))
{
    die("Cannot open $export_file");
}
$export_file = "xlsfile://tmp/example.xls";

What is xlsfile:// ? The class's author said that. It is protocol to generate Excel file.

I cannot find example.xls in any folder on my PC. If I change xlsfile://tmp/example.xls into absolute path like xlsfile://C:/temp/example.xls or any another, an error:

Quote:
Warning: fopen(xlsfile://c:/temp/example.xls) [function.fopen]: failed to open stream: "xlsStream::stream_open" call failed in...
(view source is $fp = fopen($export_file, "wb"); )
How to fix to get generated file?

I use Windows XP Service Pack 2. The web server is localhost use AppServ 2.5.10. The web server was installed in C:\AppServ as default.

Please tell me can I get my file. Which file was generated and store on server (NOT from download).


Thank you.
__________________
http://khoancatbetong.com - Vietnamese Concrete Technician Forum
superthin is offline  
Reply With Quote
Old 08-26-2008, 12:20 PM   #2 (permalink)
The Wanderer
 
tripy's Avatar
 
Join Date: Apr 2008
Posts: 7
Thanks: 0
tripy is on a distinguished road
Default

xlsfile:// is known as a protocol for your browser. Think like http://, or ftp://, or file://
Probably, it's used by IE and excel to open an excel file without having to physically create it.

But what strikes me is that you have an unix/linux/bsd file path notation in there:
/tmp/example.xls

Try maybe to look in the temp folder of your server/user, as /tmp is the regular temp place on linux.

But by the way, it's even way simpler than that...
Simply create an html table, and send an header like this:
PHP Code:
header("Content-Type:  application/vnd.ms-excel");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
before writing the table. Excel will open the html table like it was an spreadsheet...
tripy is offline  
Reply With Quote
Old 07-25-2009, 01:01 AM   #3 (permalink)
rin
The Visitor
 
Join Date: Jul 2009
Posts: 1
Thanks: 0
rin is on a distinguished road
Default in my case..

Hellow~ :)

I think you have two files.


1. excel.php (74th row)
PHP Code:
$this->xlsfilename '/' $url['host'] . $url['path']; 
↓↓
PHP Code:
$this->xlsfilename $url['host'] . $url['path']; 
Because '/' means absolute path.
We want relative path.


2. And you have another download page like your code.
PHP Code:
// line 9 to 15 in example_export.php from the class above

require_once "excel.php";
$export_file "xlsfile://tmp/example.xls";
$fp fopen($export_file"wb");
if (!
is_resource($fp))
{
    die(
"Cannot open $export_file");


This is point!

First, 'excel.php' and 'download page' and the directory name 'tmp' located in the same directory!

Second, you must look 'tmp' directory's permission. I think this permission should be 757 at least.



english is not my native language.
so I'm hard writing english.
anything.. good luck!
rin is offline  
Reply With Quote
Old 07-25-2009, 09:48 AM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by superthin View Post
What is xlsfile:// ?
It is a custom stream wrapper written by the author of that class.

Quote:
Originally Posted by superthin View Post
I cannot find example.xls in any folder on my PC. If I change xlsfile://tmp/example.xls into absolute path like xlsfile://C:/temp/example.xls or any another, an error
It should be at C:/tmp/example.xls. The other paths fail because they are not available to be written to. The class is silly in that all paths are converted into absolute ones from the root of the main drive of the machine, not relative to the script.

It would be advisable to fix the class to work as expected; relative to the current working directory unless an absolute, full path is specified. It is also advisable to turn your error reporting to the most aggressive setting during development: like error_reporting(E_ALL | E_STRICT).
Salathe is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:44 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design