Uploading a file

How do I upload a file using perl, there are scripts out there but they are too complicated and contain too much

Thanx

Comments

  • : How do I upload a file using perl, there are scripts out there but they are too complicated and contain too much
    :
    : Thanx
    :
    :
    Please give more detail. Are you doing a CGI script or making and application? Are you using FTP?

    Sparky
  • : : How do I upload a file using perl, there are scripts out there but they are too complicated and contain too much
    : :
    : : Thanx
    : :
    : :
    : Please give more detail. Are you doing a CGI script or making and application? Are you using FTP?
    :
    : Sparky
    :

    Well I have figured out how to do FTP but I would like to know how to do it in other protocols. this is just from a simple web page.

  • sub UploadFileLHRT
    {
    my $LocalPathName = $_[0]; #This is also the local file handle
    my $RemotePathName = $_[1];
    my $TransferType = $_[2];

    if(($TransferType eq "ascii") || ($TransferType eq "a"))
    {
    open(UFLHRTFILE, "> $RemotePathName");
    select UFLHRTFILE;
    while (<$LocalPathName>)
    {
    s/
    //g; #This is for unix
    print;
    }

    select STDOUT;
    close($LocalPathName);
    close(UFLHRTFILE);
    }
    else #If binary
    {
    open(UFLHRTFILE, "> $RemotePathName");
    while (($b_read = read($LocalPathName, $bufr, 1024)))
    {
    print UFLHRTFILE $bufr;
    }
    close($LocalPathName);
    close(UFLHRTFILE);
    }
    chmod(0777,$RemotePathName);
    }


    Heres how its used:

    my $file_handle = param('[b]file_to_upload[/b]');
    my $name_on_server = $file_handle;
    my $transfer_type = param('[b]transfer[/b]');
    UploadFileLHRT($file_handle, $name_on_server, $transfer_type);

    Heres the explaination:

    Although you may have thought that opening a file on someone elses computer would be hard, in this case its not. Newer browsers like ie 4 and up etc, will simply pass the handle of a file that has been selected with a FILE input type in a web page, to the script. So, all you do is treat it like a regular file handle, ALSO, the file name is passed, but both the handle and the name are contained in the same variable.

    For the function(sub) above, $file_handle is the handle that the script recieved, $name_on_server is just for readability and is there to hold the file name, so in this instance, the name on the server will be the same as it was on the client. $transfer_type is exactly the same as an ftp client, 'a' for ascii and 'b' for binary upload.

    Heres some html:


    Upload




    File:


    Transfer Type:

    Ascii

    Binary







  • sorry 'bout this, i'm a deek, I didn't realize it wasn't there. For the file upload described in the other post the opening form tag needs the ENCTYPE attribute set to "multipart/form-data"



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories