Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

where is it writing to

Posted on 2011-02-21
4
Medium Priority
?
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
Patricck earned 1000 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 71

Assisted Solution

by:Chris Dent
Chris Dent earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

610 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