A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Looking For A Simple Upload Script...

  1. #1
    Junior Member
    Join Date
    Jan 2009
    Posts
    11

    Cow Icon Looking For A Simple Upload Script...

    I am looking for a file upload script that is easy to setup and will put the files in a folder of my choosing on my websites server.
    CGI and PHP are OK, but the script would have to be real simple to set up if im going to use it. Maybe something in javascript?

    please help me out and send me some links, thanks in advance.

  2. #2
    Below is a simple file upload script.Within the script itself, you specify:

    1. Where the uploaded file is stored (may be blank to store in the same directory where the script is installed).
    2. The file name (optional).
    3.The URL of a "thank you" page (also optional).

    Do all edits with an ASCII/plain text word processor like NotePad or TextWrangler.

    Here is the script:
    Code:
    #!/usr/bin/perl
    ##############
    #
    # Simple Upload
    # Version 1.0
    # Copyright 2007 Bontrager Connection, LLC
    #
    # License Agreement linked from /master/ 
    #    must be agreed to before installation or use of this software.
    #
    # See http://BontragerConnection.com/ for more information 
    #    about this Simple Upload software.
    #
    ##############
    
    # Leave next two lines as is.
    use strict; # To specify a strict use of variables and functions
    use CGI; # To handle much of the upload work.
    
    ##################
    # Customizations are below.
    #
    # This script will display an upload form if launched 
    #    without uploading a file.
    # The source code of the form thus displayed may be copied 
    #    and pasted into a web page of your creation.
    #########
    
    
    ##################
    ##  C U S T O M I Z A T I O N S
    #########
    
    # # # Three customizations may be made.
    
    #
    # One:
    #
    # Specify the directory where the file shall be stored.
    # A path beginning with "/" means relative to document root 
    #    directory. Otherwise, it means relative to directory 
    #    where script is installed.
    # Blank means store in the same directory where this script 
    #    is installed.
    # NOTE: Directory must exist and have sufficient permissions.
    
    my $StoreFileDirectory = '';
    
    #
    # # Two:
    #
    # Specify the file name the uploaded file is to be stored as.
    # Blank means store file with same name as uploaded file.
    # NOTE: File will overwrite any existing with same 
    #       name as file being stored.
    
    my $StoreFileName = '';
    
    #
    # # # Three:
    #
    # Specify the URL of the "thank you" page to display after 
    #    form is used.
    # Blank will cause another upload file to be presented.
    
    my $ThankYouPage = '';
    
    
    #########
    ##  E N D   O F   C U S T O M I Z A T I O N S
    ##################
    
    
    # Load the contents of the form into the $FORM variable.
    my $FORM = new CGI;
    
    sub StoreUploadedFile
    {
    	# Grab the filehandle of the uploaded file.
    	my $filehandle = $FORM->upload('filename');
    	# Return false if no file uploaded.
    	return '' unless $filehandle;
    	# Grab the file name of the uploaded file.
    	my $filename = $FORM->param('filename');
    	# Strip any path information from the file name.
    	$filename =~ s!^.*[/\\]!!;
    	# Determine file storage name and directory location.
    	$StoreFileName = $filename unless $StoreFileName =~ /\w/;
    	$StoreFileDirectory .= '/' if $StoreFileDirectory =~ /\w/ and $StoreFileDirectory !~ m![\\/]$!;
    	$StoreFileDirectory = "$ENV{DOCUMENT_ROOT}$StoreFileDirectory" if $StoreFileDirectory =~ m!^[\\/]!;
    	# Store the file.
    	my $buffer;
    	open UPLOADED,">$StoreFileDirectory$StoreFileName";
    	binmode UPLOADED; # for Win/DOS operating systems
    	while(read $filehandle,$buffer,1024) { print UPLOADED $buffer; }
    	close UPLOADED;
    	# Return true.
    	return 1;
    } # sub StoreUploadedFile
    
    
    sub PresentUploadForm
    {
    	# Notice the enctype attribute of the form.
    	print "Content-type: text/html\n\n";
    	print <<FORM;
    <html><body>
    
    <form 
       name="UploadForm" 
       enctype="multipart/form-data" 
       action="http://$ENV{SERVER_NAME}$ENV{REQUEST_URI}" 
       method="POST">
    <input type="file" name="filename" size="55">
    <br>
    <input type="submit">
    </form>
    
    </body></html>
    FORM
    } # sub PresentUploadForm
    
    my $stored = StoreUploadedFile;
    exit PresentUploadForm unless $stored and $ThankYouPage;
    print "Location: $ThankYouPage\n\n";
    # end of script

  3. #3
    Junior Member
    Join Date
    Jan 2009
    Posts
    11
    thank you very much, that is exactly what im looking for.

  4. #4
    Junior Member
    Join Date
    Jan 2009
    Posts
    11
    one question though, how do I use it?
    do I have to save it as a .cgi?

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center