#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    2
    Rep Power
    0

    File Upload and Calling Cgi files


    I appreciate your help in cracking the following issue

    Functionality - A File will be uploaded from a webpage and On Form Submit The Following Cgi_script is being Called.

    The Script in turn checks for the availability of the File and does 2 conversion based on Format (6/7)
    (1) from utf16 - utf8
    (2) Replaces Tabs with Comma
    and generates the output in a File

    PROBLEM Description
    - Why does the File never gets Uploaded Only when i am adding the Conditions for File Manipulation. Otherwise the File script Works like a Charm

    - There is a Cronjob Running few minutes to set the File Permissions on the File whichever is being loaded
    But Doesnt show up anything when i do ls -al <File NAme> and i get a 500 error

    - Am i missing something Here

    Code goes as below

    #!/usr/bin/perl
    use lib '/u02/Upld';
    # End of Configurable Options.

    use CGI qw(:standard);
    $query = new CGI;
    $SAVE_DIRECTORY="/u03/upld_files";
    chop $SAVE_DIRECTORY if ($SAVE_DIRECTORY =~ /\/$/);
    $OWA_Path=$query->param("p_OWA_Path");
    $Charset=$query->param("p_charset");
    $format=$query->param("P_FORMAT");
    $p_data_source=$query->param("P_DATA_SOURCE");
    $email=$query->param("email");
    $process_id=$query->param("list_id");
    $process_id1=$query->param("list_id1");

    if ($query->param("file_01") =~ /([^\/\\]+)$/) {
    $Filename = $1;
    $File_Handle = $query->param("file_01");
    }
    $BytesRead = 0;
    $Buffer = "";
    $output67 = $SAVE_DIRECTORY . "/utf_" . $Filename;
    $infile = "$SAVE_DIRECTORY\/$Filename";


    if ($format == 6 || $format == 7) {
    system "touch $output67";
    $Convrsn="'s/\t/,/g'";

    open(FILE,"<$infile");
    while (1==1){
    ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,$atime, $mtime, $ctime, $blksize, $blocks)= stat($infile);
    $FAccs = -X $infile;
    if ($mode == 33279 && $FAccs == 1){ last; }
    }
    $line = <FILE>;
    @check = unpack("CCC",$line);
    print join(',',@check),"\n";
    close(FILE);

    if ($check[0]=255 && $check[1]=254 ){
    $Charset = "utf8";
    system "iconv -f UTF-16 -t UTF-8 $infile > $output67";
    system "perl -pi -e $Convrsn $output67";
    $outputf = $output67;
    }
    }

    $outputf = $infile;

    print "Content-type: text/html;\n\n";
    print <<__END_OF_HTML_CODE__;
    <html>
    <head><script LANGUAGE="javascript">
    <!--//
    function SubmitForm() {
    document.Up.submit(); }
    //-->
    </script>
    <title>TESTING Upload</title>
    </head>
    <body bgcolor="#FFFFFF" vlink="#0000FF" alink="#0000FF" topmargin="5" leftmargin="15" onLoad="SubmitForm();">
    <table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
    <td valign="top" align="left" width="100%" bgcolor="#FFFFFF">
    <strong><font size="2" face="Arial,Helvetica">
    <FORM NAME="Up" ACTION="$OWA_Path\Upld" METHOD="POST">
    The following files were sucessfully uploaded <br><br>
    __END_OF_HTML_CODE__

    print "<INPUT TYPE=\"hidden\" NAME=\"p_Id\" VALUE=\"$process_id\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"p_Filename\" VALUE=\"$Filename\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"p_DataSource\" VALUE=\"$p_data_source\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"p_CharSet\" VALUE=\"$Charset\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"p_Format\" VALUE=\"$format\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"p_Id2\" VALUE=\"$process_id1\">\n";

    print "&nbsp;&nbsp;&nbsp;$Filename - <br>\n";
    print <<__END_OF_HTML_CODE__;
    <br>Please wait a moment while the database is updated...<br><br>
    <INPUT TYPE="Submit" NAME="Button" Value=" Cancel ">
    </FORM>
    </td></tr></table>
    <br>
    </BODY>
    </HTML>
    __END_OF_HTML_CODE__
    Last edited by chev; July 24th, 2003 at 07:15 PM.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    2
    Rep Power
    0

    File Upload


    I got how File Upload Works in Cgi and here is the url for anybody who is looking for an answer

    http://www.perlfect.com/articles/upload.shtml

IMN logo majestic logo threadwatch logo seochat tools logo