Solved

where is it writing to

Posted on 2011-02-21
4
382 Views
Last Modified: 2013-12-25
Hello. Can someone say where the files that are being written are be written to? Is it to the directory where this script is located (cgi-bin) or to the csv directory? And how can I tell?
use strict;
use warnings;
use CGI;

my $_DOCUMENT_ROOT = 
	"C\:\\HostingSpaces\\getready\\mydomain.com\\wwwroot\\csv";


opendir DIRECT, "$_DOCUMENT_ROOT";
my @filelist = grep {$_ !~ /^\./ } readdir( DIRECT );
closedir DIRECT;

my $_report = '';
my $cgi = CGI->new ;

my $_offset = defined($cgi->param("offset")) ? $cgi->param("offset") : 0;
my $_length = defined($cgi->param("length")) ? $cgi->param("length") : 20; 
my $_action = defined($cgi->param("sub")) ? $cgi->param("sub") : "";
my $_passwd = defined($cgi->param("passw")) ? $cgi->param("passw") : '';
$_passwd = ($_passwd eq "123") ? 1 : '';

$_action = '' unless $_action;
$_action = '' unless $_passwd;
if($_action){

      if(defined($cgi->upload("upload"))){
        my $filename = "$_DOCUMENT_ROOT\\Input.csv";
        my $upload_filehandle = $cgi->upload("upload");
        open OUTFILE, ">$filename";
         binmode OUTFILE;
         binmode $upload_filehandle;
         while(<$upload_filehandle>){
            print OUTFILE "$_";
          }
        close OUTFILE;
        system("perl parse_input.pl");
       }

 system("perl mainprog.pl $_offset $_length");        
 $_report = "<br><a style=\'backgrond-color: \#f2f233; color: \#770022; font: 16px Helvetica;\' href=\'\/csv\/report.csv\'> <b> Resultant CSV file  <\/b> <\/a>&nbsp; &nbsp; <a style=\'backgrond-color: \#f2f233; color: \#770022; font: 16px Helvetica;\' href=\'\/csv\/reducedreport.csv\'> <b> Resultant CSV file 2 (condensed) \ <\/b> <\/a> <br>\n";
}

print $cgi->header;
print $cgi->start_html(-title=>'Twitter statistics');
print "<div style=\'padding: 12px 12px 12px 12px;\' > <h3> CSV files <\/h3> \n <table>";
my $_k = 0;
my $_astyle = "style=\'border: 1px solid \#eef2ff; background-color: \#fffaf2; font: 14px Georgia; margin: 12px 12px 12px 12px;\'";
foreach(@filelist){
 print "<tr>" if ($_k % 3) == 0;
 print "<td> <a $_astyle href=\'\/csv/$_\' > $_ <\/a> <\/td> \n";
 print "<\/tr>" if ($_k % 3) == 2;
 $_k++;
}
print "<\/table><\/div>\n";

print "$_report\n";

print <<HERE_GOES;

<div style='padding: 12px 12px 12px 12px; margin: 12px 12px 12px 12px;
font: 14px Arial; border: 1px solid #337799; background-color: #f7faff;
color: #002233;'>

<form method='post' action='/cgi-bin/task.cgi' enctype='multipart/form-data'>
<table><tr>
<tr><td><label for='passw'> <i><b> Password: <\/b><\/i> <\/label> </td>
<td><input type='password' name='passw' value=''> </td></tr>
<tr><td><label for='upload'> <i><b> Upload another "input.csv" <\/b><\/i> </label></td>
<td><input type='file' name='upload'> </td></tr>

<tr><td><label for='offset'> <i> Offset </i> </label></td>
<td><input type='text' name='offset' value='0' style='width: 48px;'> </td> 
</tr>
<tr><td><label for='length'> <i> Length </i> </label></td>
<td><select name='length'> 
<option value='10'> 10 </option>
<option value='20' selected> 20 </option>
<option value='30'> 30 </option>
<option value='40'> 40 </option>
<option value='50'> 50 </option>
<option value='60'> 60 </option>
</select></td>                
</tr>
<tr><td colspan='2'> <input type='submit' name = 'sub' value='Submit'> 
</td></tr>
</table>
</form>
</div>
HERE_GOES

print $cgi->end_html;

Open in new window

0
Comment
Question by:onyourmark
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
Patricck earned 250 total points
ID: 34941733
It Should be the:
"C\:\\HostingSpaces\\getready\\mydomain.com\\wwwroot\\csv"

Root is CSV folder


Regards
Patrik
0
 

Author Comment

by:onyourmark
ID: 34941750
I was told the following

"I have looked at the perl code and it appears that the task.cgi and
it's helper perl programs are writing the files report.csv and
reducedreport.csv in the cgi-bin directly rather than the csv
directory. Therefor the hyperlinks on the resultant page are pointing
to the wrong place. It is better not to write directly into the
cgi-bin as those files are expected to be executable, so I would
suggest changing the output file to the proper relative path
..\csv\report.csv "
0
 
LVL 70

Assisted Solution

by:Chris Dent
Chris Dent earned 250 total points
ID: 34941801

The code you have posted does not generate either of the files quoted in the note above.

It could be that this generates them:

system("perl parse_input.pl");
system("perl mainprog.pl $_offset $_length");

The first is most likely, but all we can say at the moment is that Input.csv is written to the OUTFILE handle, and that's in $_DOCUMENT_ROOT (C:\HostingSpaces\getready\mydomain.com\wwwroot\csv).

Chris
0
 

Author Closing Comment

by:onyourmark
ID: 34941823
Thanks!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

747 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

13 Experts available now in Live!

Get 1:1 Help Now