473,791 Members | 3,122 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Not being able to search

5 New Member
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 1857
KevinADC
4,059 Recognized Expert Specialist
What does happen when you run your script?
May 1 '07 #2
stunna
5 New Member
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 Recognized Expert Specialist
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 New Member
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 Recognized Expert Top Contributor
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 New Member
i used what you suggested but i get an error message "fileparse( ): need a valid pathname"
May 3 '07 #7
stunna
5 New Member
Sorry, just sorted it out. Thanks guys for your help, i reallly appreciate
May 3 '07 #8
miller
1,089 Recognized Expert Top Contributor
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
4699
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 (PHONE_LIST, "_+")) { Console.WriteLine (phoneNumber); } } Output: 495.1000
10
1796
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 and migration from V7.2 to 8.2 FP8. Best regards, Jean-Marc
28
3182
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 linear search the best here(for loop from beginning to end of array)? It seems like some other search algorithm like binary or whatever would be of no benefit on this data set.
5
1732
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 3 queries you'll see results at the bottom. For me, those results look like this: api (4), darren (1), xml (12), battlepanda (1), war+on+drugs (6), stupid (1), moron (1), nightmare (1), hell (1), mijkuynbvfsds (1),
9
2632
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 before c++). that was 15 days ago IIRC. now that with my skill set i went on to search for a good book. my knowledge is limited to the following: 1.) "A gentle introduction to symbolic computation" - David S. Touretzky
4
3459
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 provide RSS feeds nor are they really interested in providing consistent and informative content (what we (almost) all are looking for). .. I have been mostly programming java lately. THis is how I see such an API could -very basically indeed- be...
1
1280
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, and in that SUB-FORM I added all the FIELDS I want to view. However, when I try to type in data into the FIELDS I am searching for, it does not let me. I would just like to type in an ID or the name of the Document and have Access PULL that...
0
5578
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 exception is: javax.ejb.EJBException: Connection to pool failed! - com.ibm.websphere.ce.cm.StaleConnectionException: SQL1224N The database manager is not able to accept new requests, has terminated all requests in progress, or has terminated your...
1
1533
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, Sort sort) throws IOException Problem : I cant able to search the word. If the word contain special character like , %BF It just taken that special character a empty space and search the remaining character
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10419
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9023
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.