What you want can be very well made using perl scripts.
I have a freeware cgi-script (perl) for you that does exactly what you
want.
The script is called "upload parser". You can limit the size of the
transfered pictures, the location on your domain where the pictures
will be stored and so on. At the end of an upload the picture is
displayed in the browser - nice to check if all has gone well.
The script comes in two seperate cgi-scripts.
You could install this script seperately to offer a picture upload or
you can study the routines used in the script to include them in you
own script.
The scripts require a chmod to 755, the directory where the images are
stored chmod 777.
Now the source codes:
1st script - store under the name "upload.pl" in your cgi-bin
#!/usr/bin/perl
require "parser.pl";
##############################################
# Upload-Parser 1.11
# (c) 2001-2002 by Reiner SilberStein
# www.skriptoase.de
#
# Dieses Programm ist Freeware. Wir würden
# uns jedoch freuen, wenn Sie bei der Ver-
# wendung dieses Skriptes einen Link zu
# unseren Seiten setzen würden:
# www.skriptoase.de
#
##############################################
$cgiurl = "http://www.your-domain.com/cgi-bin/"; # location of script
$pathofpictures = "/usr/home/domain.../imgages/"; # server path for
the images
$urlofpictures = "http://www.your-domain.com/images/"; # URL for the
images
$maxuploadfilesize = 100000; # max.size for the images in Byte -
necessary !
$pathtemplate = "/htdocs/template.htm"; # server path to the template
not necessary to use one
&parseform;
$var = length($uploadfile);
if ($var <= $maxuploadfilesize) {
open upload, ">$pathofpictures$uploadfilename" || die ("Error");
binmode upload;
print upload $uploadfile;
close upload;
$piclink = $urlofpictures.$uploadfilename;
$text = "Upload complete<br>\n";
$text = $text."Link to the image: <a
href=$piclink>$piclink</a><br><br>\n<img src=\"$piclink\">";
}
else {
$text = "File is too big!\n";
}
# Template laden
if ($pathtemplate) {
open(template, "<$pathtemplate") || die "Content-type:
text/html\n\nGnP: Fehler beim Öffnen von $pathtemplate!";
@template=<template>;
close(template);
@template = split (/<INHALT>/, join("", @template));
}
$text = $template[0]."<!-- Upload-Parser (www.skriptoase.de)
-->\n".$text."\n<!-- Upload-Parser -- Ende -->\n".$template[1];
# ausgeben
print "Content-type: text/html\n\n".$text;
exit;
2nd script store as "upload.pl" in your cgi-bin
#!/usr/bin/perl
##############################################
# Upload-Parser 1.11
# (c) 2001-2002 by Reiner SilberStein
# www.skriptoase.de
#
# Dieses Programm ist Freeware. Wir würden
# uns jedoch freuen, wenn Sie bei der Ver-
# wendung dieses Skriptes einen Link zu
# unseren Seiten setzen würden:
# www.skriptoase.de
#
##############################################
sub parseform {
if($ENV{'REQUEST_METHOD'} eq 'GET') {
$formdata = $ENV{'QUERY_STRING'};
}
else {
binmode STDIN; # Nur fuer Win-Server bedeutend
read(STDIN, $formdata, $ENV{'CONTENT_LENGTH'});
}
if (substr($formdata,0,29) ne "-----------------------------") {
@pairs = split(/&/, $formdata);
foreach $pair (@pairs) {
($key, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$key =~ s/(\.x)|(\.y)//; # Schaltet Koordinaten-Angaben von
Image-Buttons aus
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form{$key} = $value;
}
}
else {
@parts = split /-----------------------------.{9}/, $formdata;
foreach (@parts) {
# Bei folgender If-Anweisung kann das Format auch noch weiter
eingeschraenkt werden, z.B. "image/gif" - zur Analyse einfach mal
$formdata mit ausdrucken lassen!
if ($_ =~ "Content-Type: image/") {
@file = split /\n/, $_, 5;
while ($file[1] =~ /\\/) { $file[1] =~ s/^.*\\//; }
$file[1] =~ s/"//g;
chop $file[1];
$uploadfilename = $file[1];
chop $file[4]; chop $file[4];
$uploadfile = $file[4];
}
elsif ($_ =~ "name=") {
($var, $key, $value) = split(/\"/, $_);
$value =~ s/([\n\f\r])//g;
$key =~ s/(\.x)|(\.y)//; # Schaltet Koordinaten-Angaben von
Image-Buttons aus
$form{$key} = $value;
}
}
}
}
return 1;
All you need now to use it is the call of the script from you html
page.
the form tag I use looks like that:
<FORM METHOD="POST" ACTION="http://www.your-domain.com/cgi-bin/upload-parser/upload.pl"
ENCTYPE="multipart/form-data">
<!-- For Upload : Methode "POST" und Enctype "multipart/form-data" -->
<FONT face="Arial, Helvetica" size="2" color="#000066">Select
File:</FONT><BR>
<INPUT TYPE="file" NAME="uploaded_file" SIZE=30 MAXLENGTH=80>
<INPUT TYPE="hidden" NAME="hidden" VALUE="versteckt">
<INPUT TYPE="submit" NAME="button" VALUE="upload">
</FORM>
I hope that this solves your problem. The script is by far the best
one I found on the web. If you should have any problems please post a
clarification request before rating my answer.
till-ga
Search Strategy
The original script (with german commenst however) can be downloaded
at:
( http://www.silbersteine.de ) |
Request for Answer Clarification by
horseradish-ga
on
31 Oct 2003 05:15 PST
Thanks for this, it looks like just what I need. However, I do have a
couple of questions:
1. I think perhaps you've made a small error as you say:
1st script store as "upload.pl" in your cgi-bin
and
2nd script store as "upload.pl" in your cgi-bin
Should the 2nd one be called parser.pl? I have guessed that this is
the case, but when I try to run it, I'm getting a 500 server error.
See it in action so far at http://www.redjam.com/uploadpic.html
2. How would I incorporate it into my existing form, which already has
a <form action etc...> command? I assume I'd put my existing form data
processing script into upload.pl? Would I call my form.cgi from within
upload.pl or would I just have the entire script in full along with
the upload.pl script too? Would it go before or after processing the
image upload info? You can see my existing form at
http://www.redjam.com/testform.html. I'd like to add the image upload
bit to the bottom of it.
Thanks for your help, it looks quite exciting, I hope we can get it to
work!!
|
Clarification of Answer by
till-ga
on
31 Oct 2003 05:49 PST
Ups. Sorry for the mistake I made. Your guess is correct of course.
The 2nd script must be stored as parser.pl
Including two form tags in your html file should not be a problem. All
you got to do is explain the function of the second button.
You can place the button anywhere you like to see it on the page.
The processing order is given by the sequence the buttons are pressed.
As the actions are different you must use two form tags.
The other way -which is by far more complicated- is trying to combine
your form.cgi with the routines given in the upload script.
But why ? Those customers who want to upload images won´t see a
problem in sending the text info first and then upload the images.
You could split the whole thing up in two different pages (one for the
text data and one for the image upload) and make a link to the
"images upload" page.
till-ga
|
Request for Answer Clarification by
horseradish-ga
on
05 Nov 2003 14:18 PST
Thanks for your help. I will need to send the pics with the rest of
the info at the same time as it would be messy to submit twice, plus
it would give two results and they may not be identifiable as being a
pair.
Still perhaps I can ask that as another question to someone else.
In the meantime, I still need to get your original code working. I did
rename the files, so I have in my cgi-bin a folder called
'upload-parser' (set to chmod 777), which contains two files:
'parser.pl' and 'upload.pl' (both set to chmod 755). The html browse
page is at http://www.redjam.com/uploadpic.html. If you use it, you'll
see it returns an error 500: internal server error.
Can you help me work out why this is happening please? Thanks very much
|
Request for Answer Clarification by
horseradish-ga
on
05 Nov 2003 14:27 PST
Also I have set the folder for the images (www.redjam.com/feverapps)
to chmod 777 as you said.
I see there's a line:
$pathtemplate = "/htdocs/template.htm"; # server path to the template
not necessary to use one
Shall I just take this out, if it's not necessary?
|
Clarification of Answer by
till-ga
on
06 Nov 2003 06:49 PST
There´s a little directory error in you form tag.
As you write in your request the perl-scripts are not in the
cgi-bin
directory, but in the
cgi-bin/upload-parser
directory.
So your form tag should be:
<FORM METHOD="POST" ACTION="http://www.redjam.com/cgi-bin/upload-parser/upload.pl"
ENCTYPE="multipart/form-data">
I´m shure it will solve this problem.
Please leave the line
$pathtemplate = "/htdocs/template.htm"; # server path to the template
not necessary to use one
in the code. I´m not really shure what happens if you take the line out.
till-ga
|
Request for Answer Clarification by
horseradish-ga
on
06 Nov 2003 13:41 PST
Sorry, I changed the form tag as I took the files out of that folder
to see if it would make it work. Originally, I had the files in that
folder, with the correct line and it didn't work you see. I'll change
it back now so you can see it still doesn't work even when that line
is as it should.
I tried placing an alert message in the very first part of upload.pl,
before it even gets to the 'require' line and that doesn't even work.
It's as though it can't even get to upload.pl somehow, yet I have
definitely set permissions on it to 755.
|
Clarification of Answer by
till-ga
on
06 Nov 2003 23:39 PST
I´m a little bit confused about the problems you have getting the
script running. I got thios script running on several accounts of
customers.
Please try an upload using my server to see that the scripts work:
http://www.stoffel-kueppers.de/formular.htm
Please use the following code for the form then:
<HTML>
<HEAD>
<TITLE>Upload-Parser</TITLE>
</HEAD>
<BODY link="#444444" vlink="#888888" alink="#888888">
<DIV align="center"><FONT face="Arial, Helvetica" size="6"
color="#000066">Upload-Parser
</FONT><br><br>
<FONT face="Arial, Helvetica" size="2" color="#000066">Upload images
</FONT>
<FORM METHOD="POST" ACTION="http://www.redjam.com/cgi-bin/upload.pl"
ENCTYPE="multipart/form-data"> <!-- Für Upload zwingend: Methode
"POST" und Enctype "multipart/form-data" -->
<FONT face="Arial, Helvetica" size="2" color="#000066">Select
file:</FONT><BR>
<INPUT TYPE="file" NAME="uploaded_file" SIZE=30 MAXLENGTH=80>
<INPUT TYPE="hidden" NAME="hidden" VALUE="versteckt">
<INPUT TYPE="submit" NAME="button" VALUE="upload">
</FORM>
<FONT face="Arial, Helvetica" size="1"><A
href="http://www.silbersteine.de">Upload-Parser © 2001 by
SilberSteine
</A></FONT>
</BODY>
</HTML>
If it´s still not working then I will write to the editors of Google
Answers and ask them for permission to contact you by mail as it could
be necessary to send you the original completely unmodified files.
We WILL get this to work !
till-ga
|
Clarification of Answer by
till-ga
on
07 Nov 2003 00:35 PST
Please have a look at
http://sourceforge.net/projects/upload-parser/
The authors of the scripts have released a new version under the GNU
general public license.
Obviously they have chamned some features, one of them being the
intergration of the upload abilities into existing perl scripts. That
could be exactly what you´ve been looking for.
And there will be support in english at sourceforge.net.
I hope this helps to solve the problem finally.
till-ga
|
Request for Answer Clarification by
horseradish-ga
on
10 Nov 2003 09:11 PST
I'm sorry but this just isn't working. I think the problem is that
you're advising me to use someone else's script but without really
understanding how it works yourself. I do appreciate that you have
tried to help me but I still do not have the working result that I
needed.
I'm now looking at other options for this.
Thank you very much anyway.
|
Clarification of Answer by
till-ga
on
10 Nov 2003 10:05 PST
I am sorry that you are not satisfied with the solution I gave.
Did you try the installed script on my domain to see that the scripts
work ? Did you have a look at the new features in the updated version
of the script ?
till-ga
|