Uploading Image Script

Discussion in 'Installation' started by modeler4547, Nov 12, 2004.

Thread Status:
Not open for further replies.
  1. modeler4547

    modeler4547 Guest

    Everyone:
    I have a file 'upload.cgi' on my server to upload images.
    I have 'upload.html' on the server which browses for an image and sends to server.

    When I use upload.html and send an image, the response page shows that the filesize sent is tabulated but the file is not actually placed on the server.

    If I manually place an image on the server then attempt an upload of that same image, the confirmation image appears along with the filesize, but it was still not placed on the server.

    I have checked where it is sending the file and it appears to be a valid location. The root of my server.

    Can anyone tell me where in this code the problem is?

    Here is the acutal file on the server if you want to test it.
    http://www.washwriter.org/upload.html

    upload.cgi....................................................
    #!/usr/bin/perl -w

    use CGI;
    $CGI::pOST_MAX = 500000; # Added as an example - limit POST to 500k

    my $q = new CGI; # Create new query object

    my $filename = $q->param("pic");
    my $upload_filehandle = $q->upload("pic"); # Corrected
    my $upload_dir="";

    $filename =~ s/.*[\/\\](.*)/$1/;
    print $q->header ("text/html" );

    open UPLOADFILE, ">$upload_dir/$filename";
    binmode UPLOADFILE; # to specify binary file operations on this filehandle

    my $total_bytes = 0;

    while (my $bytes_read = read($upload_filehandle, $buffer, 1024)) {
    print UPLOADFILE $buffer;
    $total_bytes += $bytes_read;
    }
    close $upload_filehandle;
    close UPLOADFILE;

    print "<html>";
    print "<head>";
    print "<title>Thanks..!!!</title></head>"; # note closing head tag
    print "<body>";
    print "<P>Thanks for uploading your photo!</P>";
    print "<P>Your photo:</P>";
    print "<P>Where sent</P>";
    print "<img src=\"/$upload_dir\" border=\"0\">";
    print "<img src=\"/$filename\" border=\"0\">";
    print "<p>Size of photo is $total_bytes bytes.</p>"; # Added line if desired.
    print "</body>";
    print "</html>";

    upload.html....................................................
    <HTML>
    <HEAD></HEAD>
    <BODY>
    <FORM ACTION="/cgi-bin/upload.cgi" METHOD="post" ENCTYPE="multipart/form-data">
    Photo to Upload: <INPUT TYPE="file" NAME="pic">
    <br><br>


    <INPUT TYPE="submit" NAME="Submit" VALUE="Submit Form">
    </FORM>
    </BODY>
    </HTML>
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
Thread Status:
Not open for further replies.

Share This Page