Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use utf8;
- #use URI::Escape;
- #use Encode qw/from_to/;
- use Mojolicious::Lite;
- use DBI;
- app->attr(dbh => sub {
- my $self = shift;
- my $data_source = "dbi:mysql:database=ftp_search;host=localhost";
- my $user = "root";
- my $password = "root";
- my $dbh = DBI->connect($data_source,$user,$password,{RaiseError => 1});
- return $dbh;
- });
- get '/' => sub {
- my $self = shift;
- $self->render(text => 'It works!');
- };
- get '/find' => sub {
- my $self = shift;
- $self->render(template => 'find');
- };
- get '/find_result' => sub {
- my $self = shift;
- my $qw = $self->param('qw');
- my $r1 = $self->param('r1');
- if(defined($qw)){
- my $dbh = $self->app->dbh;
- $dbh->do('SET names utf8');
- my $search=$dbh->prepare(qq{SELECT name,type,size,ftp FROM ftp_search_d WHERE name LIKE '%$qw%' LIMIT 0,50});
- $search->execute();
- my $array;
- while (my ($name,$type,$size,$ftp) = $search->fetchrow_array()){
- $array .= "<td>" . $name . "</td><td>" . $type . "</td><td>" . $size . "</td><td>" . $ftp ."</td>";
- }
- $search->finish;
- $self->render(text => "$array");
- }else{
- $self->redirect_to('find');
- }
- };
- app->start;
- __DATA__
- @@ find.html.ep
- <form action='<%= url_for 'find_result'%>' method='get' >
- <input type='text' name='qw' size='60'/></input>
- <input type='submit' value='Поиск' class='submit'/><br>
- По файлам:<input type='radio' name='r1' value='0'/ checked="checked"></input>
- По папкам:<input type='radio' name='r1' value='1' /></input>
- </form>
Add Comment
Please, Sign In to add comment