By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,361 Members | 3,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,361 IT Pros & Developers. It's quick & easy.

script carrying over file with no problem but not text

cassbiz
100+
P: 202
Could use some help here.

This script is carrying over an image just fine but the text isn't coming over. can you see why it is not working????

from the form I want to carry over two lines of text and I can't find the error on why it isn't working.

Any help is greatly appreciated.

Here is the form
Expand|Select|Wrap|Line Numbers
  1. <form enctype="multipart/form-data" action="./cgi/upload.pl" method="post">
  2.  
  3. <table cellspacing="0" cellpadding="2" width="100%" border="0">
  4. <tr>
  5. <td colspan="2" align="center"><font face="verdana,arial,helvetica,geneva">Upload your company logo</td>
  6. </tr>
  7. <tr>
  8. <td colspan="2" align="center">
  9. <font face="Verdana, Arial, Helvetica, sans-serif">Select an Image to Upload</font>&nbsp;&nbsp;
  10. <input type="file" name="userfile" /></td>
  11. </tr>
  12. <tr>
  13. <td colspan="2" align="center">
  14. <font face="Verdana, Arial, Helvetica, sans-serif">Your Description Line 1</font>
  15. &nbsp;&nbsp;<input type="text" name="description1" size="30" value="" maxlength="20" /><br />
  16. <font face="Verdana, Arial, Helvetica, sans-serif">Your Description Line 2</font>
  17. &nbsp;&nbsp;<input type="text" name="description2" size="30" value="" maxlength="20" /></td>
  18. </tr>
  19. <tr>
  20. <td colspan=2 align="center"><input type="submit" value="Upload Logo and Continue to Step 2"> <input type="reset" value="Start Over"></td>
  21. </tr>
  22. <tr>
  23. <td colspan="2" align=center>
  24.  
  25. <table bordercolor="#ffcc00" cellspacing="0" cellpadding="3" border="2" width="450">
  26. <tr>
  27. <td align="center">
  28. <table border="0">
  29. <tr>
  30. <td align="center"><font face="Verdana, Arial, Helvetica, sans-serif"
  31. color="#00cc0c">
  32. The size of the image may not be more than 50 KB,<br />
  33. and the image must be a JPG or GIF image.</font>
  34. </td>
  35. </tr>
  36. </table>
  37. </td></tr></table>
  38. </td>
  39. </tr>
  40. </table></form>
  41.  
Here is the script
Expand|Select|Wrap|Line Numbers
  1. # Let's define our variables first off..
  2. $| = 1;
  3. $upath = "/custom/images1/"; #with trailing /
  4. $upath_url = "/custom/images1"; #no trailing /
  5. $uindex = "/custom/images1/temp/"; #with trailing /
  6. $uimagedir = "/custom/images/"; #with trailing /
  7. $underlay_front = "/custom/images/t_front.jpg";
  8. $underlay_back = "/custom/images/t_back.jpg";
  9. $tempfile = $upath . $ENV{'REMOTE_ADDR'};
  10. $nofileerror = "/custom/uploaderror.html";
  11. $reg_pl = "/custom/cgi/register.pl";
  12. $recipient = "webmaster\@yourweb.com";
  13. $subject = "Wicked T\'s";
  14. $required = "Name,email";
  15. $redirect = "/custom/up.html";
  16. $sitename = "Rourke\'s Wicked T\'s";
  17. $db_url = "/custom/data/registered_users.dat";
  18. $db_fields = "Name,email,Uploaded_Pic,shirt_style";
  19.  
  20.  
  21.  
  22. # The following reads in the CGI buffer, and writes it to a temporary file
  23. # which will be used later.
  24.  
  25. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  26. open (x,">$tempfile");
  27. print x $buffer;
  28. close (x);
  29.  
  30.  
  31. # Now, time to open the temporary file and process it!
  32. open (temp,$tempfile);
  33.  
  34.  
  35. # Gotta pull the MIME/multipart separator line out.. We'll keep the 15
  36. # digit number for later...
  37. $_ = <temp>;
  38. ($vernum) = /(\d+)/;
  39.  
  40.  
  41. # Next line of the file contains the filename in the format:
  42. #     filename="C:\windows\win.ini"
  43. # We'll just keep the part inside the quotes...
  44. $_ = <temp>;
  45. $filetemp = $1 if (/filename=\"(.*)\"/);
  46.  
  47.  
  48. # The filename currently has the full pathname to the file in it.. We
  49. # don't want that! .. First we grab the last word after the backslash (for
  50. # PC systems), then we're gunna grab the last word after the forward slash
  51. # (unix systems).. Don't worry, it works.
  52. @pathz = (split(/\\/,$filetemp));
  53. $filetempb = $pathz[$#pathz];
  54. @pathza = (split('/',$filetempb));
  55. $filename = $pathza[$#pathza];
  56.  
  57.  
  58. #------------------------------------------------------#
  59. # START: Filter to allow only GIF and JPG files and
  60. # less than 50K Size
  61. #------------------------------------------------------#
  62.  
  63. $extension = (split(/\./,$filename))[-1];
  64. if ($extension !~ /(gif|jpg)/i )        {
  65.  print "Content-Type: text/html\n\n";
  66.         print "<html>\n<title>Error!</title>\n";
  67.         print "<body bgcolor=\"\#ffffff\" text=\"\#000000\">\n";
  68.         print "<DIV ALIGN=CENTER><H4><FONT COLOR=RED>ERROR - FILE TYPE NOT ALLOWED\!</FONT></H4><P>\n";
  69.         print "You can only upload a jpg or gif file.<BR>\n";
  70.         print "<b>or</b><BR>\n";
  71.         print "This routine does not work with your version of Internet Explorer.<P>\n";
  72.         print "Press your browsers BACK button to try again.</DIV>";
  73.         print "</html>\n";
  74.         exit 0;
  75. }
  76.  
  77. if ($ENV{'CONTENT_LENGTH'} >= 50000) {
  78.         print "Content-Type: text/html\n\n";
  79.         print "<html>\n<title>File size is too large!</title>\n";
  80.         print "<body bgcolor=\"\#ffffff\" text=\"\#000000\">\n";
  81.         print "<DIV ALIGN=CENTER><H4><FONT COLOR=RED>ERROR - IT'S TOO BIG\!</FONT></H4><P>\n";
  82.         print "Sorry but you are not authorized to upload files over 50k.<br>\n";
  83.         print "Please only upload files less than 50k in size.<br><br>";
  84.         print "<FORM><INPUT TYPE=\"button\" NAME=\"back\" VALUE=\"Start Over\" onClick=\"history.go(-1)\"></FORM>\n";
  85.         print "</DIV></html>\n";
  86.         exit 0;
  87. }
  88.  
  89. #------------------------------------------------------#
  90. # END: Filter to allow only GIF and JPG files and
  91. # less than 50K Size
  92. #------------------------------------------------------#
  93.  
  94.  
  95. # And, if the filename is nothing, we'll clean everything up and give them
  96. # a pretty error message
  97. if ($filename eq "") {
  98.         print "Location: $nofileerror\n\n";
  99.         close(temp);
  100.         `rm $tempfile`;
  101.         }
  102.  
  103.  
  104. # Now that we know the name of the file, let's create it in our upload
  105. # directory..
  106. open (outfile, ">$upath$filename");
  107.  
  108.  
  109. # Now we don't care about the Content-type of this, so we'll pass that up
  110. $junk = <temp>;
  111. $junk = <temp>;
  112.  
  113.  
  114. # And we're gunna read/write all the lines of our file until we come to the
  115. # MIME-multipart separator, which we'll ignore.
  116. while (<temp>) {
  117.    if (!(/-{28,29}$vernum/)) {
  118.                 print outfile $_;
  119.                 }
  120.    }
  121.  
  122. # We're done with that.. Let's close things up and remove that temp file.
  123. close (temp);
  124. close (outfile);
  125. `rm $tempfile`;
  126.  
  127.  
  128. # And bust da HTML
  129.  
  130. print "Content-type: text/html\n\n";
  131. print <<"EOF";
  132.  
  133. <html>
  134. <head>
  135. <title>$sitename</title>
  136. </head>
  137. <BODY text="#000000" bgcolor="#ffffff" link="#0000ff" vlink="#0000ff" alink="#ff00ff">
  138.  
  139.  
  140. <FORM action="$reg_pl" method="post">
  141. <input type="hidden" name="subject" value="$subject">
  142. <input type="hidden" name="redirect" value="$redirect">
  143. <input type="hidden" name="required" value="$required">
  144. <input type="hidden" name="recipient" value="$recipient">
  145. <input type="hidden" name="Uploaded_Pic" value="$upath_url/$filename">
  146. <input type="hidden" name="append_db" value="$db_url">
  147. <input type="hidden" name="db_fields" value = "$db_fields">
  148. <input type="hidden" name="db_delimiter" value = "|">
  149.  
  150.  
  151. <TABLE border="0" cellspacing="0" cellpadding="0" width=500>
  152.  
  153. <TR>
  154. <TD align=center colspan=2><h1>Shirt Front</h1>
  155. <img src=$underlay_front width="450">
  156. <span style="position: absolute; left: 270; top: 155"><img src=$upath_url/$filename width="80"></span>
  157. </TD>
  158. </TR>
  159.  
  160.  
  161. <TR>
  162. <TD align=center colspan=2><h1>Shirt Back</h1>
  163. <img src=$underlay_back width="450">
  164. <span style="position: absolute; left: 165; top: 660"><img src=$upath_url/$filename width="200"></span>
  165. </TD>
  166. </TR>
  167. <tr>
  168. <td colspan="2" align="center">
  169. <font face="Verdana, Arial, Helvetica, sans-serif">Your Description Line 1</font>
  170. &nbsp;&nbsp;<input type="text" name="description1" size="30" value="$description1" maxlength="20" /><br />
  171. <font face="Verdana, Arial, Helvetica, sans-serif">Your Description Line 2</font>
  172. &nbsp;&nbsp;<input type="text" name="description2" size="30" value="$description2" maxlength="20" /></td>
  173. </tr>
  174. <TR>
  175. <TD align="right">Name: </TD>
  176. <TD align="left"><INPUT type="text" name="Name" size="40"></TD>
  177. </TR>
  178. <TR>
  179. <TD align="right">Email Address: </TD>
  180. <TD align="left"><INPUT type=text name="email" size=40></TD>
  181. </TR>
  182. <TR>
  183. <TD align="right">Your City: </TD>
  184. <TD align="left"><INPUT type=text size="40" name="City"></TD>
  185. </TR>
  186. <TR>
  187. <TD align="right">Comments: </TD>
  188. <TD align="left"><TEXTAREA name="Features" rows="5" cols="40" wrap=virtual></TEXTAREA></TD>
  189. </TR>
  190. <TR>
  191. <TD colspan=2 align=center><INPUT type="submit" value="Finish and Send Image"> <INPUT type="reset" value="Reset this Page">  <INPUT TYPE="button" NAME="back" VALUE="Start Over" onClick="history.go(-1)"></TD>
  192. </TR>
  193. </TABLE>
  194. </FORM>
  195. </center>
  196.  
  197. </BODY>
  198. </html>
  199.  
  200.  
  201. EOF
  202.  
  203. ;
  204.  
Apr 27 '08 #1
Share this Question
Share on Google+
4 Replies


KevinADC
Expert 2.5K+
P: 4,059
That is the oddest perl based CGI script I ever seen. That type of scripting would have been before even the cgi-lib module was written, which is more than 10 years ago. I would look at how you are parsing the temp file.
Apr 27 '08 #2

cassbiz
100+
P: 202
Yeah the script is old, if you know of another script that uploads and displays an image along with text, I would appreciate the location of it.
Apr 28 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
Yeah the script is old, if you know of another script that uploads and displays an image along with text, I would appreciate the location of it.
If you know some perl you can adapt the script in this article I wrote. You will need to add the text fields you want to save along with the file. If you are totally unfamiliar with the CGI module you would want to read the CGI documentation.

http://bytes.com/forum/thread672398.html
Apr 28 '08 #4

cassbiz
100+
P: 202
Thank you for sending me over to the 'help' file. Will get back to you if I have any problems.
Apr 28 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.