#1
  1. No Profile Picture
    miguelgarcia
    Guest
    Devshed Newbie (0 - 499 posts)
    I am looking for a way to give users the ability to uplaod files. (html, gif's and jpg's).

    The idea is that I want user to be able to upload html documents, along with any referenced images.

    There will probably be some java/javascript necesary to get it done, but there has to be some code samples out there somewhere. Anyone have any ideas.

    The help I've received so far has been very appreciated.
  2. #2
  3. No Profile Picture
    Projecto EINet
    Guest
    Devshed Newbie (0 - 499 posts)
    Try to use PHP3 if you can. It's very easy.

    Goto http://www.cgi-resources.com and see some Web Advert programs in Perl. It's a kind of program that usually uses Upload for banners.

    Another place is http://www.scriptsearch.com. They have a lot of samples too.

  4. #3
  5. No Profile Picture
    Imo
    Guest
    Devshed Newbie (0 - 499 posts)
    perldoc CGI

    (The CGI module for perl). In there you'll find:

    print $query->filefield('uploaded_file','starting value',50,80);

    And more information.
  6. #4
  7. No Profile Picture
    AjayLulia
    Guest
    Devshed Newbie (0 - 499 posts)
    I have used a program i am sending to u

    check the file the file is below

    #This script is used to upload a file where it is a Txt for a binary file
    #coz the file is opend first through open function and then changed the mode using
    # a function binmode().
    ###################################################################################
    #
    #Author: Ajay Lulia
    #E-Mail: ajaylulia@hotmail.com
    #
    ###################################################################################
    BEGIN {
    $userid = "ID_number"; # --> This Number is the specific ID
    # --> ID number assigned to you on your
    # --> Unix System.

    $groupid = "ID_number"; # --> This Number is the specific Group
    # --> ID number assigned to people with
    # --> your access level on your Unix
    # --> system.

    #
    # --> You can gain your $userid and
    # --> $groupid by typing 'id' at your
    # --> UNIX prompt. (GID = Group Id,
    # --> UID = User Id).


    $path = "c:/netscape/suitespot/ksdocs/publications/";
    #
    # --> The $path variable should contain the
    # --> directory that this script will place
    # --> uploaded files into. It should NOT have
    # --> a trailing forward slash.

    $url = "ftp://proto.kotaksec.com/publications/";
    #
    # --> $url should be the URL which corresponds
    # --> to the $path defined above. And same
    # --> as the $path variable, it SHOULD NOT
    # --> have a trailing forward slash.

    $overwrite = "1"; # --> Set this value to '1' to allow
    # --> overwriting of existing files.
    # --> Set this value to '0' to dis-allow
    # --> the overwriting of existing files.
    # -->
    # --> NOTE:
    # --> Existing files WILL NOT be over-
    # --> written unless they are given the
    # --> permissions 'a+rw'. An error message
    # --> will return to users who try to over-
    # --> write files which are protected.

    $success_url = "http://proto.kotaksec.com/admin/upload_doc_right.html";
    #
    # --> This contains the URL people should be
    # --> redirected to once they have completed
    # --> a successful upload. If empty, a page
    # --> will be generated, which includes
    # --> statistics.

    $exclusive_lock = 2; # --> DO NOT CHANGE THIS VALUE - It should
    # --> be set to '2'

    $unlock_lock = 8; # --> DO NOT CHANGE THIS VALUE - It should
    # --> be set to '8'

    $pub_path{'Morning Flash'} = "morningflash";
    $pub_path{'Initiative Coverage Report'} = "icr";
    $pub_path{'Company Updates'} = "companyupdates";
    $pub_path{'Notes From'} = "notesfrom";
    $pub_path{'Non Rated Coverage'} = "nrc";
    $pub_path{'Sector Reports'} = "sectorreport";
    $pub_path{'Strategy Reports'} = "strategyreport";
    $pub_path{'Earnings Guide'} = "earningsguide";

    }


    #
    # End of Configurable Options.
    # ---------------------------------------------------------------------
    # ---------------------------------------------------------------------
    # --> Do Not Change Anything Below This Line. <-- #
    # ---------------------------------------------------------------------
    # ---------------------------------------------------------------------

    $| = 1;


    &GetInput;
    &Process_File;
    &Redirect_User;

    # ---------------------------------------------------------------------
    sub GetInput {
    #
    # --> Sub: &GetInput();
    #
    # --> Return:
    #
    # --> Summary:
    # Loads CGI module, assigns $filename the filename the
    # file should be saved as.
    #

    use CGI;
    $query = new CGI;

    $publication = $query->param('publication');

    $path = $path.$pub_path{$publication};

    $url = $url.$pub_path{$publication};


    if ($query->param('save-as-filename') !~ /^[ t]*$/) {
    $filename = $query->param('save-as-filename');
    } else {
    $filename = $query->param('upload_file');
    }

    #
    # END OF SUB
    #
    }

    # ---------------------------------------------------------------------

    sub Process_File {
    #
    # --> Sub: &Process_File();
    #
    # --> Return:
    #
    # --> Summary:
    # Takes all the input, determines if the user is using
    # the appropiate browser, then extracts the filename,
    # and saves the file. Uploaded files are chmodded to 644,
    # and given ownership to the user defined in $userid and
    # $groupid.
    #

    &Exit_Not_A_Netscape_User if ($ENV{'HTTP_USER_AGENT'} !~ /^Mozilla/[432]/);

    if ($filename =~ ///) {
    @array = split(///, $filename);
    $real_name = pop(@array);
    } elsif ($filename =~ //) {
    @array = split(//, $filename);
    $real_name = pop(@array);
    } else {
    $real_name = "$filename";
    }

    $outfile = "$path" . "/" . "$real_name";

    $filename = $query->param('upload_file');

    &Exit_File_Exists if ((-e "$outfile") && (!$overwrite));

    if (!open(OUTFILE, ">$outfile")) {
    print "Content-type: text/plainnn";
    print "-------------------------n";
    print "Error:n";
    print "-------------------------n";
    print "File: $outfilen";
    print "-------------------------n";
    print "There was an error opening the Output Filen";
    print "for Writing.nn";
    print "Make sure that the directory:n";
    print "$pathn";
    print "has been chmodded with the permissions '777'.nn";
    print "Also, make sure that if your attemptingn";
    print "to overwrite an existing file, that then";
    print "existing file is chmodded '666' or better.nn";
    print "The Error message below should help you diagnosen";
    print "the problem.nn";
    print "Error: $!n";
    exit;
    }
    binmode(OUTFILE);
    while ($bytesread = read($filename,$buffer,1024)) {
    $totalbytes += $bytesread;
    print OUTFILE $buffer;
    }

    close($filename);
    close(OUTFILE);

    # chmod (0644, "$outfile");
    # chown ($userid, $groupid, "$outfile");

    #
    # END OF SUB
    #
    }

    # ---------------------------------------------------------------------

    sub Redirect_User {
    #
    # --> Sub: &Redirect_User();
    #
    # --> Return:
    #
    # --> Summary:
    # Redirects users to the success url defined in
    # $success_url the program then terminates.
    #

    if ($success_url) {
    print "Location: $success_urlnnn";
    #print "Content-type: text/htmlnn";
    #print "$publication";
    #print $pub_path{'Morning Flash'};
    exit;
    } else {
    print "Content-type: text/htmlnn";
    print <<END_OF_HTML_CODE;

    <HTML>
    <HEAD>
    <TITLE>Thank You</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFFF">
    <H1><TT><B>Thank You</B></TT></H1><br>

    END_OF_HTML_CODE

    print "Thanks for the upload. You uploaded one file, which was $totalbytes bytes in size.n";
    print "It has been saved. You can access it with the url: <a href="$url/$real_name">$url/$real_name</a>n";
    print "<p><hr size=1><center>Script By <a href="mailto:jeffc@terminalp.com">Jeff Carnahan</a> of <a href="http://www.terminalp.com/scripts/">Jeff's Scripts</a></center></BODY></HTML>n";
    exit;
    }

    #
    # END OF SUB
    #
    }

    # ---------------------------------------------------------------------

    sub Exit_Not_A_Netscape_User {
    #
    # --> Sub: &Exit_Not_A_Netscape_User();
    #
    # --> Return:
    #
    # --> Summary:
    # This user is not using a version of Netscape claiming
    # to be above version 2.0...
    #

    print "Content-type: text/htmlnn";
    print <<END_OF_HTML_CODE;

    <HTML>
    <HEAD>
    <TITLE>Error!</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFFF">
    <H1><TT><B>Error! - Invalid Browser</B></TT></H1><br>
    Sorry, but you must use Netscape 2.0+ to use this system. Please
    use the back button on your browser and try again.
    </BODY>
    </HTML>

    END_OF_HTML_CODE

    exit;

    #
    # END OF SUB
    #
    }

    # ---------------------------------------------------------------------


    sub Exit_File_Exists {
    #
    # --> Sub: &Exit_File_Exists();
    #
    # --> Return:
    #
    # --> Summary:
    # This user is trying to upload a file with a filename
    # that is already in use, and this script is set not to
    # overwrite existing files.
    #

    print "Content-type: text/htmlnn";
    print <<END_OF_HTML_CODE;

    <HTML>
    <HEAD>
    <TITLE>Error!</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFFF">
    <H1><TT><B>Error! - File Exists</B></TT></H1><br>
    Sorry, but this system is not allowed to overwrite existing files. The filename
    you have selected is already in use where file-uploads are allowed. Please use the
    back button on your browser, rename the file and try again.
    </BODY>
    </HTML>

    END_OF_HTML_CODE

    exit;

    #
    # END OF SUB
    #
    }

    # ---------------------------------------------------------------------
    # EOF



    ------------------

    Ajay Lulia.
  8. #5
  9. No Profile Picture
    thelem
    Guest
    Devshed Newbie (0 - 499 posts)
    Can I have permission to use this script in a bigger script which may be sold please? If not I will find another way of doing it, I cannot afford to pay.

    Thanks,
    Lemming

IMN logo majestic logo threadwatch logo seochat tools logo