in reply to Re: Why I can not acess files outside cgi-bin directory?
in thread Why can I not acess files outside cgi-bin directory?

Hi, thank you schodckwm, here is my testing code. I used active perl 5.81 on windows xp. It seems that the I need use \\ to represent the '\' on windows to represent directory delimiter. The code works if I use $filename = "test.txt";.
#!c:/perl/bin/perl -w use CGI; # only files in cgi-bin directory works? #filename = "C:\\Program Files\\Apache Group\\Apache2\\htdocs\\project +s\\Generate_Conc_xls\\test.txt"; $filename = "test.txt"; $header1 = "Content-disposition: attachment; filename=$filename\n"; $mime_type = "application/octet-stream"; #print header for downloading file to client print $header1; print "Content-Type: $mime_type\n\n"; #print content to client file open (READ, "<$filename"); binmode READ; local $/; print <READ>; close(READ);
Thanks a lot.

Replies are listed 'Best First'.
Re^3: Why I can not acess files outside cgi-bin directory?
by skx (Parson) on Mar 24, 2005 at 22:05 UTC

    Change your code to test that your open succeeds:

    open( READ, "<$filename" ) or die "Failed to open $filename - error $! +";

    That might provide some clues in your webservers error log.

    Steve
    ---
    steve.org.uk
      It doesn't work because it seems that the server is always thinking, openning or reading file there and the status bar stuck at ~50%. Really confused!
        Maybe the file is big. Slurping the whole file into memory can cause the process to go swap-bound.

        Try copying it a chunk at a time. (Use File::Copy or DIY).

        { local $/ = \1024; local *_; while (<READ>) { print }; }