first part: list all media files from a directory and print them to html page creating a form, where each file name gets its checkbox element. (I could find a script tree.pl, that makes a linked list of files with file sizes etc.)
second part: using the form obove, I'd like to be able to type a name ($name) in a text field, select some media files from the list (using checkboxes), optionally add a $linkname and $comment to each file and hit save button, to save a simple text file with a name: $name.txt, containing a list of all selected files. where each element has a form of something like:
<li><a href:"path to file">$name - $comment</a></li>
Could anyone help me with this. I could also donate creating such a script if it doesn't exist already.
<edit>wow, that was too much code -- please see Forum Charter [webmasterworld.com] and try to use specifics -- Thanks, coopster</edit>
[edited by: coopster at 9:54 pm (utc) on Sep. 28, 2005]
[edit reason] removed code [/edit]
I suppose that the second part should be much easier, as the input for this script would already be precisely formated by the first one. I don't feel capable of writing a script on my own, all I can do for now is mostly carefull editing, so I need someone to either direct me to a script that may be adapted for this task, or tell me how much work is it to program it and how much is it worth.
Blind_virgin.mp3=selected
Heaven.mp3=selected
Judyta.mp3=selected
Julia.mp3=selected
Kawdor.mp3=selected
Kurhan.mp3=selected
MKB_Orch2.mp3=selected
Statique.mp3=selected
Suncloud.mp3=selected
Vocara.mp3=selected
of course I need to get rid of those "=selected" parts, which are remains of the form's selection boxes, but I dont know how. I tried the "s/'=selected'//g;" line but it does not work.
#!/usr/bin/perl
require "cgi-lib.pl";
&ReadParse(*input);
# save file
$file = "$input{'userlist'}.inc";
open(FILE, ">$file") ¦¦ die("n$file: $!nn");
shift @input; # delete file name from array
shift @input; # delete button name from array
# Print the item to webpage
print &PrintHeader;
foreach $musicclip (@input)
{ print "$musicclip <br>\n"; }
# Print the item
foreach $musicclip (@input)
{ print FILE "$musicclip\n"; }
s/'=selected'//g; # delete =selected
close(FILE);
#!/usr/bin/perl
require "cgi-lib.pl";
&ReadParse(*input);
you will be better off using:
#!/usr/bin/perl
use CGI qw/:standard/;
you then access the form inputs using the param function:
my $foo = param('bar');
where 'bar' is the name of a form field.
Here is a link to the CGI docs:
[perldoc.perl.org...]
the module you are using (cgi-lib.pl) is pre perl 5, and should no longer be used whenever possible.
Here's my script. It writes a file which is ready to be included through ssi:
#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
my @clips = param('mp3');
my @name = param('userlist');
my @title = param('title');
# Print list to webpage
print header;
{ print "<h3>@title</h3>\n"; }
foreach my $mp3 (@clips)
{ print "<a href=\"/members/media/$mp3\" class=\"light\">$mp3</a><br>\n"; }
# save file
$file = "@name.inc";
open(FILE, ">$file") ¦¦ die("n$file: $!nn");
# Print the item
{ print FILE "<h3>@title</h3>\n"; }
foreach my $mp3 (@clips)
{ print FILE "<a href=\"/members/media/$mp3\" class=\"light\"><b>$mp3</b></a><br>\n"; }
close(FILE);
open(FH,">path/to/$file") or die "$!";
this looks funny:
$file = "@name.inc";
@name is an array and will be expanded inside of double-quotes. Are you sure that's what you want?
This is my new version, but of course it does not work.
It spits out in one line: "<a href="/members/media/Blind_virgin.mp3" class="light"><b>Blind_virgin.mp3</b></a> 4857kB 7748kB 15275kB 6612kB 8973kB 7051kB 4550kB 7463kB 6169kB 13846kB<br>"
and what I need is only the corresponding file size, not the whole array.
So is there a way I could pass two values from two fields in one line of code?
#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
my @clips = param('mp3');
my @size = param('howbig');
my @name = param('userlist');
my @title = param('title');
# Print list to webpage
print header;
{ print "<h3>@title</h3>\n"; }
foreach my $mp3 (@clips)
{ print "<a href=\"/members/media/$mp3\" class=\"light\">$mp3</a><br>\n"; }
# save file
$file = "/home/members/templates/@name.inc";
open(FILE, ">$file") ¦¦ die("n$file: $!nn");
# Print the item
{ print FILE "<h3>@title</h3>\n"; }
foreach my $mp3 (@clips)
{ print FILE "<a href=\"/members/media/$mp3\" class=\"light\"><b>$mp3</b></a> @size<br>\n"; }
close(FILE);
you have:
foreach my $mp3 (@clips) {
print FILE "<a href=\"/members/media/$mp3\" class=\"light\"><b>$mp3</b></a> @size<br>\n";
}
try this:
for my $i (0 .. $#clips) {
print FILE "<a href=\"/members/media/$clips[$i]\" class=\"light\"><b>$clips[$i]</b></a> $size[$i]<br>\n";
}
for my $i (0 .. $#clips) {
print FILE qq~<a href="/members/media/$clips[$i]" class="light"><b>$clips[$i]</b></a> $size[$i]<br>\n~;
}
the tilde "~" is just a delimiter you can use others if you prefer
qq!the string!;
qq#the string#;
etc
etc
etc
<input name="mp3"
type="checkbox"
value="filename.mp3"
class="selectbox">
<a href="filename.mp3">filename.mp3</a>(4857kB)
<input type="hidden"
name="filename.mp3"
value="4857kB">
so I suppose that "foreach" method should work now:
Foreach "mp3" name, print its value (filename.mp3) and use this value as a name and print its value which is size.
Does it make any sense for you?
BTW file saving, this form will be accessible only from admin area (which means only me) so hopefully it's going to be safe there.
You have another alternative:
<input name="mp3"
type="checkbox"
value="filename.mp3::4857kB"
class="selectbox">
<a href="filename.mp3">filename.mp3</a>(4857kB)
now the values of @mp3 can be split on the :: and used to generate you links.
foreach my $mp3 (@mp3) {
my ($file,$size) = split(/::/,$mp3);
print FILE qq~<a href="/members/media/$mp3" class="light"><b>$mp3</b></a> $size<br>\n";
}
:: is just an arbitrary delimiter I picked, you could use something different.
foreach my $mp3 (@clips) {
my ($file,$size) = split(/::/,$mp3);
print FILE qq#<a href="/members/media/$file" class="light"><b>$file</b></a> $size<br>\n#;
}
[webmasterworld.com...]