Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi, Its me again, the guy with the original problem. Right, heres the code I use so far for JUST uploading a file. It does not use CGI.pm. I wanted all the code on one page so I could see how it worked using my own variable names, etc. Here it is:
#!/usr/bin/perl print "Content-type: text/html\n\n"; #SET MAXIMUM FILE SIZE ################################################# $maxfilesize = 30508; # 30.2kb #CHECK FILE SIZE ################################################# $len = $ENV{'CONTENT_LENGTH'}; if ($len > $maxfilesize) { print "file is bigger than 30.2kb, sorry\n"; exit; } #SET PATH VARIABLES ################################################ $| = 1; $upath = "/absolute/path/to/upload/dir/"; $uindex = "/absolute/path/to/upload/dir/upload.index"; $tempfile = $upath . $ENV{'REMOTE_ADDR'}; #READ IN BUFFER AND WRITE TO TEMP FILE ################################################ read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); open (x,">$tempfile"); print x $buffer; close (x); #OPEN TEMP FILE AND PROCESS IT ################################################ open (temp,$tempfile); #PULL OUT MIME/MULTIPART ################################################ $_ = <temp>; ($vernum) = /(\d+)/; # Next line of the file contains the filename in the format: # filename="C:\windows\win.ini" # KEEP ONLY PART WITHIN QUOTES ################################################ $_ = <temp>; $filetemp = $1 if (/filename=\"(.*)\"/); #REMOVE FULL PATH NAME ################################################ @pathz = (split(/\\/,$filetemp)); $filetempb = $pathz[$#pathz]; @pathza = (split('/',$filetempb)); $filename = $pathza[$#pathza]; #IF FILENAME IS BLANK, SHOW ERROR MESSAGE ############################################### if ($filename eq "") {<br> print "Oops, the you did not give a valid file name\n\n"; close(temp); `rm $tempfile`; } #CREATE FILE IN UPLOAD DIR ############################################### open (outfile, ">$upath$filename"); # Now we don't care about the Content-type of this, so<br> we'll pass +that up $junk = <temp>; $junk = <temp>; #READ/WRITE ALL APART FROM MIME/MULTIPART BIT ############################################## while (<temp>) { if (!(/-{28,29}$vernum/)) { print outfile $_; } } #ALL DONE, CLOSE AND PRINT SUCCESS MSG ############################################## close (temp); close (outfile); `rm $tempfile`; print "Your file <i>$filename</i> has been successfully<br> transferre +d to this site.<br>\n"; exit;

So theres the code, anyone know how I can pass through 3 VARIABLES too?. I do need the variables for security but at this stage the user has already logged in. I just like to constantly pass throught a username and password so that the .cgi script cant be accessed on its own without going through the login.

Im pretty new to all this so I really am sorry if I sound like a gimp. lol Really appreciate more help on this, thanks for all the replies everyone, Ill make sure I put you on the Thanks Page. :)


In reply to Re: Re: File Upload - AND hidden values by Anonymous Monk
in thread File Upload - AND hidden values by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-24 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found