473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Not being able to search

5
Hi there, i want to implement a a system to search for a file in a folder using the file name and if its there, i want it to be displayed. I have one through a couple of books on how to implement this but still, it does not open the file.

Expand|Select|Wrap|Line Numbers
  1. #!C:/Perl/bin/perl
  2.  
  3. use strict;
  4. use CGI qw(:standard);
  5. use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
  6. use DBI;
  7. use CGI;
  8.  
  9. print header();
  10.  
  11. my $ps = param('ps');
  12. my $name = param('name');
  13.  
  14. if ($ps eq "search") {
  15.     if ($name eq "") {
  16.         print "<p> No search keyword";
  17.     } else {
  18.         open(FILE, "<C:/docs/media/$name") or print "<p> File '$name' does not exist";
  19.  
  20.         while(<FILE>) {
  21.             print;
  22.         }
  23.  
  24.         close FILE;
  25.     }
  26. }
  27.  
  28.  
  29. print <<END1;
  30. <HTML>
  31.  
  32. <HEAD>
  33. <TITLE>SEARCH/UPLOAD</TITLE>
  34. </HEAD>
  35.  
  36. <style type="text/css">
  37. .box1 {
  38.     margin-left: 0px;
  39. }
  40. </style>
  41.  
  42. <BODY bgcolor = "#003366">
  43. <form action="" method="post" enctype="multipart/form-data" name="uploadform">
  44. <img src="unilogo.gif" border=0> </img>
  45. <br/>
  46. <br/>
  47. <br/>
  48. <table border="0" cellpadding="2" cellspacing="5">
  49.  
  50. <font color="yellow"><h1>Media File Upload/Search System</h1></font>
  51.  
  52.     <tr>
  53.      <td>
  54.      <strong><font color="white" size="5px">Search for Media Files</font></strong>
  55.      </td>
  56.      </tr>
  57.      <tr>
  58.      </tr>
  59.      <tr>
  60.      <td>
  61.      <table class=box1><tr><td><input name="name" SIZE=50></td>
  62.      <td>
  63.      <input name="ps" type="hidden" value="search">
  64.      <input name="search" type="submit" value="Search" size="30">
  65.      </td>
  66.      </tr>
  67.      </table>
  68.      </tr>
  69.      </td>
  70.     </tr>
  71.  
  72. </table>
  73. <table>
  74. <tr>
  75. <td ALIGN="left">
  76. <a href="uploadpic.pl"><FONT color=c0c0c0 ><strong>Upload Pictures</font></a>
  77. </td>
  78. </tr>
  79. </table>
  80.  
  81. <table>
  82. <tr>
  83. <td ALIGN="left">
  84. <a href="uploadso.pl"><FONT color=c0c0c0 ><strong>Upload Music</font></a>
  85. </td>
  86. </tr>
  87. </table>
  88.  
  89. <table>
  90. <tr>
  91. <td ALIGN="left">
  92. <a href="uploadvid.pl"><FONT color=c0c0c0 ><strong>Upload Videos</font></a>
  93. </td>
  94. </tr>
  95. </table>
  96.  
  97. <table>
  98. <tr>
  99. <td ALIGN="left">
  100. <a href="login.pl"><FONT color=c0c0c0 ><strong>Sign-out</font></a>
  101. </td>
  102. </tr>
  103. </table>
  104.  
  105. </form>
  106. </body>
  107. </html>
  108.  
  109. END1
  110.  
  111.  
  112. sub dienice {
  113.     my ($msg) = @_;
  114.     print "<h2>Error</h2>\n";
  115.     print $msg;
  116.     exit;
  117. }
  118.  
  119. sub dbdie {
  120.     my ($package, $filename, $line) = caller;
  121.     my $errmsg = "Database error: $DBI::errstr<br> called from $package $filename line $line";
  122.     &dienice($errmsg);
  123. }
Above is how far i've gone, please can anyone help me on this.

Stunna
May 1 '07 #1
8 1840
KevinADC
4,059 Expert 2GB
What does happen when you run your script?
May 1 '07 #2
stunna
5
When i run the script, it does not open the file specified nor attempt to open a file, it just displays the error message that the file does not exist even though i put in a fcorrect file name that exists. It simply does not attempt to search for the file. Actually, am trying to implement a system that searches a folder for a file and displays it. Thanks for your interest
May 2 '07 #3
KevinADC
4,059 Expert 2GB
change this line:

Expand|Select|Wrap|Line Numbers
  1. open(FILE, "<C:/docs/media/$name") or print "<p> File '$name' does not exist";
to:

Expand|Select|Wrap|Line Numbers
  1. open(FILE, "<C:/docs/media/$name") or die "Can't open 'C:/docs/media/$name' : $!";
  2.  
and see what gets printed. If you are entering a valid filename and perl can't open it and the path and filename is correct, I don't know what the problem is.
May 2 '07 #4
stunna
5
Thanks very much for your help so far. I think the problem is when i uploaded the file, it stored the file path and not the file name. Do you know how to strip of the file path or directory tree from the file name so that only the filename is stored. And usually when searching for a file, one might not know the filepath.
May 3 '07 #5
miller
1,089 Expert 1GB
Hi stunna,

Yes, use the File::Basename core library.

Expand|Select|Wrap|Line Numbers
  1. use File::Basename qw(basename);
  2.  
  3. my $filename = "whatever your full path plus filename is";
  4.  
  5. my $basename = basename($filename);
  6.  
- Miller
May 3 '07 #6
stunna
5
i used what you suggested but i get an error message "fileparse(): need a valid pathname"
May 3 '07 #7
stunna
5
Sorry, just sorted it out. Thanks guys for your help, i reallly appreciate
May 3 '07 #8
miller
1,089 Expert 1GB
Sorry, just sorted it out. Thanks guys for your help, i reallly appreciate
Your welcome. Glad you were able to figure it out.

- Miller
May 3 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

58
by: Jeff_Relf | last post by:
Hi Tom, You showed: << private const string PHONE_LIST = "495.1000__424.1111___(206)564-5555_1.800.325.3333"; static void Main( string args ) { foreach (string phoneNumber in Regex.Split...
10
by: Jean-Marc Blaise | last post by:
Dear all, Will we be able to apply FP8 (that comes out end of January) directly without obligation to go thru FP7a or will we have to step thru FP7a ? I wish to know the answer for both 8.1...
28
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
5
by: lawrence k | last post by:
Here is the thing. When you go to this page: http://www.accumulist.com/index.php?search%5BallFields%5D=api I've put in some HR tags in the HTML to separate the 3 different queries. After those...
9
by: arnuld | last post by:
hai folks, well, it's me again and again, i am asking questions. anyway, with your help i have finalised that i will start learning c++ (as you told me that i do not need to know any OO language...
4
by: onetitfemme | last post by:
Say, people would like to log into their hotmail, yahoo and gmail accounts and "keep an eye" on some text/part of a site .. I think something like that should be out there, since not all sites...
1
by: TheDataGuy | last post by:
Using MS ACCESS 2002 Problem - I developed a form, and within that FORM, I added a SEARCH BUTTON, and then I created a SUB-FORM, so when an end user clicks on the FORM it will POP-UP the SUB-FORM,...
0
by: narayan2586 | last post by:
Hi all, When ever i am trying to connect my application it's giving below error message: RemoteException occurred in server thread; nested exception is: java.rmi.RemoteException: ; nested...
1
by: Ragavendran | last post by:
Hi, I am using this method for search: Query =org.apache.lucene.queryParser.QueryParser.parse(String arg0) throws ParseException Hits = org.apache.lucene.search.Searcher.search(Query query,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.