CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> CodeCharge.Discussion

 Uploading files to www site in CC - Perl solution posted

Print topic Send  topic

Author Message
David A. Lee
Posted: 07/20/2001, 10:23 AM

Since noone has answered my post a few days ago I had to do some
actual work *BY MYSELF* <shudder> ...
In case anyone else is in the same situation as I ... here's what I found.

Question: How to upload a file from a CC page to the server using Perl ...

Answer: Someone posted an example using PHP ... however,
this doesnt work in perl. The perl implemenation does not support
file uploads whatsoever. Understandably as the POST data is in a totally
different format then normally used ...

What I did to make this work was write a small custom perl program
to do the upload. This *could* be embedded into a CC page as a Before Open
event ... but I choose to simply have this as a general purpose utility
program
not associated with CC.


First on the Client page (possibly in a "Custom Footer" for a form) embeed
code
like the following.

<FORM ENCTYPE="multipart/form-data" ACTION="upload.cgi" METHOD=POST>
Or attach file: <INPUT NAME="myfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Attach File">
</FORM>


You will have to agument this to pass other values to identify the file,
or the user or session or whatever. This will just send the file to a script
"upload.cgi".

Then here is the perl code for "upload.cgi" - Note: this is not usable
'as-is'
It is just a proof-of-concept. This code copies the file to the fixed name
"/tmp/s"
You will want to copy it somewhere else based on perhaps some additional
<INPUT> field above. Also this perl code 'appears to fail' as it doesnt
write
anything to stdout. It needs to atleast write a redirection header
Location: xxxxx\r\n\r\n

to look decent and to interop with CC ... (Left as an excersize to the
reader,
I'll be doing this today in my code).
Finally this code requires a recent version of the "CGI" perl module which
you
can get from www.cpan.org

FYI: I have tested this code *as is* with a image file (JPG) and it worked
great.
No bytes were lost or corrupted ... binary files worked fine.

Server: Solaris / Apache 1.3
Client : IE 5.0



---------- upload.cgi -----------------------

#!/usr/local/bin/perl
use diagnostics;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Fcntl qw(:DEFAULT :flock);

$CGI::DISABLE_UPLOADS = 0;

my $q = new CGI;

# Get the form vars we need
my $file = $q->param("myfile");

open S ,">/tmp/s" ;
#print S $file . "\n" ;


# Initialize other vars
#my $tmpfilename = $q->tmpFileName();
my $fh = $q->upload("myfile");
my $bytesread;
my $buffer;

my $bytesread;
my $buffer;
while ($bytesread=read($fh,$buffer,1024)) {
print S $buffer;
}
close S;
----------------------------------------------------------------------------

~




--------------------------------------------------
David A. Lee
Dal Enterprises Inc.
dave@calldei.com
http://www.calldei.com


   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.