Upload Textfiles

Hi ! How can I make it possible for my users to upload textfiles ?
Please post me a source here. No URL, please !

regards
ItsMe
ItsMeAsked:
Who is Participating?
 
maneshrConnect With a Mentor Commented:
in order to restrict the size of the file, you can modify the code that i have provided. in that code i am counting the size of the file too. ($size+=$bytesread; ) so immediately after this you could say

if ($size > 200){
  close($DocLocation);
  `rm /tmp/$WebFileName`;
  print "The uploaded file exceded the specified limit<br>\n";
  exit;
}

you are right when you say "perhaps its possible to set no binmode, so exe's will be destroyed ?"

But think of this scenario, the file is less than 200K and is an exe file. it would be corrupted but still uploaded. do you want that corrupted file to eat unnecessary disk space??

in order to store the html tags too you can use a small "trick/cheat".
when the file is being uploaded, search for any html tags and just replace < with &lt; and > with &gt;(Eg. <body> would &lt;body&gt;).

Now when you want to display the file it would show it exactly as it should be!!
0
 
maneshrCommented:
here goes..........

==========upload.html=============
<form ENCTYPE="multipart/form-data" action="/cgi-bin/upload.pl" Method=POST>
Attach:<input name="doc" type="file">
<BR>
<P>
<INPUT TYPE=SUBMIT NAME=action VALUE="Upload Only!">
</form>

===========upload.pl========================

#!/usr/local/bin/perl

use CGI;

$query=new CGI;

$DocLocation=$query->param('doc');


$WebFileName = "UpdateGroupFile.htm";
print "Content-type: text/html\n\n";

`rm /tmp/$WebFileName`;
open(MYFILE,"> /tmp/$WebFileName") || die $!;
binmode MYFILE;
while($bytesread=read($DocLocation,$data,1024)){
  $size+=$bytesread;
  print MYFILE $data;
}
close(MYFILE);
close($DocLocation);

`chmod 777 /tmp/$WebFileName`;

print "<B>$DocLocation has been uploaded</B><br>\n";
print "<B>Size = ",$size," byte(s)</B><BR>\n";
0
 
ItsMeAuthor Commented:
Thanks ! Is it possible to just accept normal plain text files ?
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
maneshrCommented:
sure. what file needs to be uploaded is based on users decision.
so as long as the user knows that the file is textual, thats fine.

Alternately you can put down a policy saying that you will only allow upload of files with the extension of .txt. but then any one can rename a .exe file to a .txt file & circumvent your policy.

Bottomline, you cannot filter files based on their type using HTML.
0
 
ItsMeAuthor Commented:
Hmmm, perhaps its possible to set no binmode, so exe's will be destroyed ? How can I prevent the user from uploading files which are bigger than lets say 200 KB ?
I already thought of using textareas to transmit the text. that would be pretty cool, but how can I print out already transmitted textfiles in the textareas ? my problem is that they include html tags which confuse the browser ...

regards
ItsMe
0
 
ItsMeAuthor Commented:
oh, I want to upload the files from a local system to the server. Is it possible to open a file-open-dialog ?
0
 
ItsMeAuthor Commented:
that it ! thanks. At my first try I only replaced the first "<" tag but not ">"...
0
All Courses

From novice to tech pro — start learning today.