Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am creating a file transfer app that will allow users to both upload and download files. I want users to be able to download a file, just by clicking on the link. I know this is so simple, but I must be an idiot. It will not work, but when I copy the html source generated by my script and save it as a html file, it works. I am using the entire path of the file as the link. Also, when I attempt to click on the link nothing happens. Even if I right click and try to open the link in a new window, nothing happens. I am using CGI::App and this is one of my run modes. Here is the snipet:
my $self = shift; my $q = $self->query(); my $template = $self->load_tmpl("directory_tt.html"); my $dir = $q->param('dir') ? $q->param('dir') : 'c:/projects/p +ractice/dir'; my $parent_dir = $q->param('parent') ? $q->param('parent') : ' +c:/projects/practice/dir'; opendir(DIR, $dir) or die "cannot open dir $dir"; my (@dir, @files); while (defined(my $file = readdir(DIR))){ next if $file =~/^\./; my $full_path = "$dir/$file"; if (-d $full_path){ $file = "<IMG src=/icons/folder.gif>&nbsp;<a h$full_path>$file</a>"; my %row = ( file => $file) +; push (@dir, \%row); } else{^M $file = qq|<IMG src=/icons/layout.png> +&nbsp;<a href="$full_path">$file</a>|; my %row = ( file => $file) +; push (@files, \%row); } } $template->param(parent=>$dir); $template->param(dir=>\@dir); $template->param(files => \@files); $template->param(dir_name=>$dir);

Replies are listed 'Best First'.
Re: href = file doesnt work within script
by duct_tape (Hermit) on Dec 24, 2003 at 16:06 UTC

    Just a guess, but I see that if the dir param is not defined then you are assigning it 'C:/projects/....'. Maybe you need to make the link include file:// since it looks like you are trying to download local files.

    Or is this a web application that is going to be used remotely? If so then you shouldn't be using the full path like that. Perhaps you should check your web server's error_log to see if any errors are being produced by this such as 404 not found. Also view the source that is output to the browser and make sure that the links look correct.

    Hope that helps

      I am using templates so there is no need for Content-Type: text/html\n\n. Though I tried it anyway. I also added the file://, but again no success. Also, there are no errors in the log. I just dont understand why I cant get something so simple to work. Ahh! Thanks for trying

        Which Template?

        From HTML::Template

        # send the obligatory Content-Type and print the template output print "Content-Type: text/html\n\n", $template->output;

        "Pain is weakness leaving the body, I find myself in pain everyday" -me

        Would lead me to believe that you are using HTML::Template. In which case, you DO need to print a content-type header to the browser.
Re: href = file doesnt work within script
by kutsu (Priest) on Dec 24, 2003 at 16:01 UTC

    I've never used CGI::App before but, did you print "Content-Type: text/html\n\n"; first thing?

    "Pain is weakness leaving the body, I find myself in pain everyday" -me

Re: href = file doesnt work within script
by Anonymous Monk on Dec 24, 2003 at 15:41 UTC
    Ignore the ^M...thats just extra crap from windows. The script is on a winodows box