Need some help with "Upload.pl".[Solved]
Hello.
I know nothing about cgi and perl, but i got this uploading script and i need help with two changes if they are possible to make.
1. How can i make "enter" or "new line" after printing this?
print ff $in;
2. It will save all uploaded txtfiles as "SAVE.txt", would like it beter if it was saved as the 5 first letters inside the uploaded txtfile "@inx".
Code:
#!/usr/bin/perl
use CGI;
$CGI::POST_MAX = 2048;
print "content-type: text/html\n\n";
binmode(STDIN);
@inx = <STDIN>;
splice(@inx,0,4);
splice(@inx,$#inx,1);
$in = join("",@inx);
$in = substr($in,0,length($in) - 2);;
open (ff,"<SAVE.txt");
@list = <ff>;
open(ff,">SAVE.txt");
binmode(ff);
print ff $in;
print ff (@list);
close(ff);
print "DONE, Uploaded Size: ".length($in)." bytes";
Many big thanks,
naitsabes
Re: Need some help with "Upload.pl".
1) print ff $in, "\n";
2) huh? First 5 letters of what?
Re: Need some help with "Upload.pl".
Thanks :)
5 first letters of "@inx",
naitsabes
Re: Need some help with "Upload.pl".
You can use that substr command to get the first 5 characters o something
my $var = substr($inx[0],0,5);
substr is the function name. the first part inside the parenthesis is the data/variable you want to get a substring out of. The next is the starting index. In this case 0 which sets the cursor before the 1st character. Then the 5 tells it to get the next 5 characters.
You can then use the $var variable to name the file
Re: Need some help with "Upload.pl".
Thanks Cander for all your help!
naitsabes