Results 1 to 2 of 2

Thread: CGI Forms - Help Required

  1. #1
    Join Date
    May 2013

    CGI Forms - Help Required


    I am very new to all this and have recently set up a website using Webplus X5 and justhost as the web host. On the website I have included a form for clients to include their Name etc and attach a document. I have been trying to correct / change the code on the form (using CGI) for a while now but I cannot get it to work.

    Please please please could someone help me, because as I said I am new to all this and have try / read everything I can but I am totally getting confused now! I have contacted the web host provided but they don't seem to want to help.

    Anyway I have included the upload script and form script (plus some of the rest of the page script - if you can help and need the rest I can post it) I have been trying to correct and would be very grateful if someone could try and direct me to how to make it work.

    Also any advice on where the forms / upload script should go would be welcome as I have read that if it is not put in the right place the whole thing will not work.

    As I said I am TOTALLY confused with it all now and really could do with some help!


    Upload script

    #!/usr/bin/perl -wT

    use strict;
    use CGI;
    use CGI::Carp qw ( fatalsToBrowser );
    use File::Basename;

    $CGI::POST_MAX = 1024 * 5000;
    my $safe_filename_characters = "a-zA-Z0-9_.-";
    my $upload_dir = "/uploads";

    my $query = new CGI;
    my $filename = $query->param("DOCUMENT1");
    my $email_address = $query->param("email_address");

    if ( !$filename )
    print $query->header ( );
    print "There was a problem uploading your document (try a smaller file).";

    my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
    $filename = $name . $extension;
    $filename =~ tr/ /_/;
    $filename =~ s/[^$safe_filename_characters]//g;

    if ( $filename =~ /^([$safe_filename_characters]+)$/ )
    $filename = $1;
    die "Filename contains invalid characters";

    my $upload_filehandle = $query->upload("DOCUMENT1");

    open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
    binmode UPLOADFILE;

    while ( <$upload_filehandle> )
    print UPLOADFILE;

    close UPLOADFILE;

    print $query->header ( );
    print <<END_HTML;
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="Generator" content="Serif WebPlus X5 (">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">
    <title>Thanks You</title>
    <style type="text/css">
    img {border: none;}
    <p>Thanks for uploading your document</p>
    <p>Your email address: $email_address</p>
    <p>Your document:</p>
    <p><img src="/upload/$filename" alt="DOCUMENT1" /></p>

    Form script

    <img src="wpimages/wp8ffdb634_06.png" width="27" height="1023" border="0" id="pcrv_15" alt="" onload="OnLoadPngFix()" style="position:absolute;left:1px;top:32px;">
    <img src="wpimages/wpcb783fe0_06.png" width="28" height="996" border="0" id="pcrv_16" alt="" onload="OnLoadPngFix()" style="position:absolute;left:771px;top:49px;">
    <div id="wp_gallery_pg_1" style="position:absolute; left:34px; top:160px; width:725px; height:310px; overflow:hidden;"></div>
    <img src="wpimages/wpe1308a55_05_06.jpg" width="727" height="31" border="0" id="pic_34" alt="" style="position:absolute;left:36px;top:1047px;">
    <img src="wpimages/wp7d8c11ab_06.png" width="339" height="483" border="0" id="qs_72" alt="" onload="OnLoadPngFix()" style="position:absolute;left:423px;top:533px;">
    <form id="form_17" name="DOCUMENT1" onsubmit="return validate_form_17(this)" action="/cgi-bin/upload2.cgi" method="post" target="_self" enctype="multipart/form-data" style="margin:0px;">
    <div id="txt_78" style="position:absolute;left:437px;top:608px;width:125px;height:21px;overflow:hidden;">
    <p class="Wp-Normal-P"><label for="edit_19"><span class="Normal-C-C1">Company Name</span></label></p>
    <input type="text" id="edit_19" name="COMPANY" value="" style="position:absolute; left:559px; top:608px; width:178px;">
    <div id="txt_2" style="position:absolute;left:437px;top:638px;width:87px;height:23px;overflow:hidden;">
    <p class="Wp-Normal-P"><label for="edit_1"><span class="Normal-C-C1">First Name</span></label></p>
    <input type="text" id="edit_1" name="NAME" maxlength="50" value="" style="position:absolute; left:559px; top:638px; width:178px;">
    <div id="txt_6" style="position:absolute;left:437px;top:668px;width:78px;height:19px;overflow:hidden;">
    <p class="Wp-Normal-P"><label for="edit_4"><span class="Normal-C-C1">Surname</span></label></p>
    <input type="text" id="edit_4" name="SURNAME" maxlength="50" value="" style="position:absolute; left:558px; top:668px; width:178px;">
    <div id="txt_1" style="position:absolute;left:437px;top:699px;width:115px;height:20px;overflow:hidden;">
    <p class="Wp-Normal-P"><label for="edit_2"><span class="Normal-C-C1">Email Address</span></label></p>
    <input type="text" id="edit_2" name="EMAIL" maxlength="100" value="" style="position:absolute; left:557px; top:698px; width:180px;">
    <div id="txt_3" style="position:absolute;left:437px;top:729px;width:94px;height:21px;overflow:hidden;">
    <p class="Wp-Normal-P"><label for="edit_3"><span class="Normal-C-C1">Tel Number</span></label></p>
    <input type="text" id="edit_3" name="PHONE" maxlength="20" value="" style="position:absolute; left:557px; top:729px; width:180px;">
    <div id="txt_79" style="position:absolute;left:437px;top:761px;width:91px;height:55px;overflow:hidden;">
    <p class="Wp-Normal-P"><span class="Normal-C-C1">Brief </span></p>
    <p class="Wp-Normal-P"><span class="Normal-C-C1">Description</span></p>
    <div id="txt_4" style="position:absolute;left:437px;top:926px;width:89px;height:39px;overflow:hidden;">
    <p class="Wp-Normal-P"><label for="file_1"><span class="Normal-C-C2">U</span><span class="Normal-C-C1">pload </span></label></p>
    <p class="Wp-Normal-P"><label for="file_1"><span class="Normal-C-C1">Document</span></label></p>
    <input type="file" id="file_1" name="DOCUMENT" size="18" style="position:absolute; left:528px; top:926px; width:217px; ">
    <input type="submit" style="position:absolute; left:664px; top:967px; width:81px; height:22px;" id="butn_1" value="Submit">
    <textarea id="text_2" name="COMMENT" rows="9" cols="20" style="position:absolute; left:556px; top:760px; width:181px; height:150px;"></textarea>
    <div id="txt_62" style="position:absolute;left:516px;top:547px;width:150px;height:43px;overflow:hidden;">
    <h2 class="Wp-Heading-2-P"><span class="Heading-2-C"><br></span></h2>
    <h2 class="Wp-Heading-2-P"><span class="Heading-2-C-C0">Get a Quote</span></h2>
    <div id="txt_81" style="position:absolute;left:61px;top:469px;width:692px;height:61px;overflow:hidden;">
    <p class="Wp-Normal-P"><span class="Normal-C-C3"> &nbsp;Welcome to First Choice Translation</span></p>
    <script type="text/javascript" src="wpscripts/jsValidation.js"></script>

  2. #2
    Join Date
    Oct 2007
    Vienna, Austria
    Well basically you would place the script to the cgi-bin directory and set its execute and read permissions. Then make a HTML page with the form. The action attribute of the form should be the URL of the script (http://example.com/cgi-bin/form-upload.cgi). Don't forget to set the $upload_dir variable to a directory (at best an absolute path) where you can upload, i.e. where the write permissions allow it. (like /var/www/example.com/upload) and the permissions should be something like 777.

    Of course all these example values are really just examples. You have to check what corresponds to your setting, like the server configuration.

    HTH GL

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10798 seconds
  • Memory Usage 2,861KB
  • Queries Executed 15 (?)
More Information
Template Usage (32):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (2)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates