Solved

Appending with Perl

Posted on 2000-05-16
10
251 Views
Last Modified: 2010-03-05
I want to append a link and text in to a html document.  The link comes from a file a user uploads and the text is a discription of the file uploaded. Thanks
0
Comment
Question by:Wild_Bill_2000
  • 5
  • 4
10 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2814196
can you pl. provide more details?

Eg. a sample html file with the link and text,
the format of the file, if any, which the user uploads.

that way one can provide you with a more accurate and exact solution.
0
 
LVL 12

Expert Comment

by:geotiger
ID: 2814323
Not quite clear about "the link comes from a file a user uploads." Do you mean the appended link will link to the file uploaded by the user?
0
 

Author Comment

by:Wild_Bill_2000
ID: 2814409
At the moment a visitor to my web site can upload a file to a pub dir, the perl that i have reads the directory and then creates links out of the file names.  here is that bit of code

opendir(DIR, "$filedir");       # $filedir from constant above      
local(@files) = readdir(DIR);   # load @files array from readdir(DIR)
    for (@files) {
      if (/\\/) {
        $oldfile = $_;          # store current element in $oldfile
        @path = split (/\\/,$oldfile); # store all path elements in @path array
        $newfile = pop(@path);  # store file name w/o path to $newfile
        # rename old filename with path info to just plain filename
        rename("$filedir"."$oldfile","$filedir"."$newfile");
      }
    next if (/^\./);            # bypass listing for current dir "."
    next if (/^index/);         # or file starting with "index"    
    print "<A HREF = "."$fileurl"."$_".">$_</A><P>\n"; # output html link to file
    }


if ($file = $query->param('filename')) {
    print "<HR>\n";
    $newfile = $file;
    if (/\\/, $file) {
          $oldfile = $file;
      @path = split(/\\/, $oldfile);
      $newfile = pop(@path);
    }
    print "<A HREF = "."$fileurl"."$newfile"."><H2>$newfile</H2></A>\n";
    open(OUTFILE, ">$filedir"."$newfile");
    while (<$file>) {
    print OUTFILE "$_";
    }
    close OUTFILE;
}


however, i  would like the perl script to just add to an html file, instead of creating one on the dynamically everytime the page loads.  Because my goal is to allow my visitors to add a description to the files they are uploading, b/c most of the files they are uploading need a couple of sentences to make a fair description.  thanks again
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2814625
i have some questions about the code that you have given.

from what i have understood from the above code, you are reading the entire directory (minus ., .. & files starting with index) and printing the remaining entires as HTML links.

Q) print "<A HREF = "."$fileurl"."$_".">$_</A><P>\n"; # output html link to file

where is the file that you are printing to?? or is the comment itself wrong??

in the next part you start with a if statement.

if ($file = $query->param('filename')) {

what is the purpose of this statement??
is it supposed to do a comparison between $file and the user entered value?? or do you want to do a simple assignment??

Also pl. explain what you are trying to do after that or at least what you want done/are expecting from that piece of code?
0
 

Author Comment

by:Wild_Bill_2000
ID: 2814758
if you go to http://www.thesolutions.com/cgi-bin/exchange.pl
you can see it in action.  I want to allow a user to also add a description to go along with the file name.  short of going through a DB i think the easiest way would be to use a 2nd html file and just append to the second html page.  I have seen this before, but i just cannot remember where.
thanks again
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:maneshr
ID: 2814939
i checked out and in fact even uploaded a file (ee.txt).

i have another Q though.

now lets say you were to convert this dynamic page (exhcange.pl) to a static page (which can be done), how would you distinguish between users and which users gets to see which file??

OR would you be serving the same static HTML file to EVERY user who comes to that page??

let me know
0
 

Author Comment

by:Wild_Bill_2000
ID: 2817226
I would be serving the same page to every user, when it is implemented it will be within a secure site, and only those with access will know its there.
0
 
LVL 16

Accepted Solution

by:
maneshr earned 100 total points
ID: 2818080
ok . here is the html file and script that should help you with what you are doing.

notice now that you would have to start with a html file instead of the PERL script.

NOTE: you will have to change the path variables in the PERL script as perl your server directory structure.

===============exchange.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Caos Research Report Upload Area</TITLE>
</HEAD><BODY><BODY BGCOLOR="#ffffff">      
<CENTER><H1>Caos Research Report Upload Area</H1></CENTER>
<HR>Please select a report to download or upload your own.<br>
Note: uploading only works with Netscape 2.0 and above
<P>
Select the <VAR>browse</VAR> button to choose a file
to upload.
<FORM METHOD="POST" action="/cgi-bin/exchange.pl" ENCTYPE="multipart/form-data"
 >
<H3>Enter the file to upload</H3><BR><INPUT TYPE="file" NAME="filename" VALUE="
" SIZE=45 ><BR>
<INPUT TYPE="reset"><INPUT TYPE="submit" NAME="submit" VALUE="Upload"></FORM>
<A HREF = http://www.thesolutions.com/incoming/data.html>data.html</A><P>
<HR>

=============exchange.pl
#!/usr/local/bin/perl

$html_file="/www/docs/manesh/exchange.html";

use CGI;

$query=new CGI;

$dir_to_store="/tmp";
$base_url="http://www.thesolutions.com/incoming/";

if (($query->param('filename')=~ /^\s+$/ || $query->param('filename')=~ /^$/)){
  print "<B>Enter file name for upload</B><br>\n";
  exit;
}else{
  $DocLocation=$query->param('filename');
  $tmp_DocLocation=$query->param('filename');

  $tmp_DocLocation=~ s/\\/\//g;
  @tmp_DocLocation=split(/\//,$tmp_DocLocation);

  $WebFileName = $dir_to_store."/".$tmp_DocLocation[$#tmp_DocLocation];
   
  open(MYFILE,"> $WebFileName") || die $!;
  binmode MYFILE;
  while($bytesread=read($DocLocation,$data,1024)){
    $size+=$bytesread;
    print MYFILE $data;
  }
  close(MYFILE);
  close($DocLocation);

  open(HTML,">>$html_file") || die $!;
  print HTML "<a href=\"$base_url$tmp_DocLocation[$#tmp_DocLocation]\">$tmp_Doc
Location[$#tmp_DocLocation]</a><BR>\n";
  close(HTML);

  print "Content-type: text/html\n\n";
  print qq{<META HTTP-EQUIV="REFRESH" CONTENT="0; URL=/manesh/exchange.html">\n
};
}
0
 

Author Comment

by:Wild_Bill_2000
ID: 2849800
Comment accepted as answer
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2850469
was there anything additional that you were looking for in the solution?

how close was my comment to your expected answer??

let me know
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now