470,862 Members | 1,699 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,862 developers. It's quick & easy.

search a web server directory

Hello All,

Please advice...I would like to do this in php, but I am open
to suggestions
I am going to place about 6 gigs of jpeg pictures on a web
server. And. I want to allow a user to go to a web page and type in
the name of a file, and if the file is found in the particular
directory on the server, the jpeg picuture will then be display in the
web browser.
I am thinking about just having a php script that will search
the particular directory, but I am not sure where to get started.
Also, will this bogg down the server.

And, in case anyone is wondering...this is being done for a
department at my university.
thanks,
Hostos
Jul 17 '05 #1
7 1781
Hostos wrote:
I want to allow a user to go to a web page and type in
the name of a file, and if the file is found in the particular
directory on the server, the jpeg picuture will then be display in the
web browser. I am thinking about just having a php script that will search
the particular directory, but I am not sure where to get started.
<?php
// this script is the action specified for the form that asks for the
// file name (or the same script that outputs the form
$filename = $_POST['filename'];
$directory = 'images/2003/';
if (isfile($directory . $filename)) {
echo '<img src="', $directory . $filename, '"/>';
} else {
echo '<p class="error">file ', $filename, ' does not exist in ',
$directory, '.</p>';
}
?>
Also, will this bogg down the server.


I don't know. If it does maybe it's better to check for filename in a
filelist text file generated automaticcaly (by a cron job?)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
"Hostos" <hm******@hotmail.com> wrote in message
news:e9**************************@posting.google.c om...
Hello All,

Please advice...I would like to do this in php, but I am open
to suggestions
I am going to place about 6 gigs of jpeg pictures on a web
server. And. I want to allow a user to go to a web page and type in
the name of a file, and if the file is found in the particular
directory on the server, the jpeg picuture will then be display in the
web browser.
I am thinking about just having a php script that will search
the particular directory, but I am not sure where to get started.
Also, will this bogg down the server.

And, in case anyone is wondering...this is being done for a
department at my university.
thanks,
Hostos


just a thought, but if its a linux platform you can try the locate command,
and pass through grep for the parent directory:

// find all house pictures
$searchString = "house";
$files = `locate $searchString | grep '/www/parent/dir/pictures/'`;

to update the locate db, type this on the command line:
updatedb

or wait untill the next day, it should be already in a cron job

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #3
CountScubula wrote:
just a thought, but if its a linux platform you can try the locate command,
and pass through grep for the parent directory:

// find all house pictures
$searchString = "house";
$files = `locate $searchString | grep '/www/parent/dir/pictures/'`;


Remember though that if the user is typing in $searchString - NEVER EVER
DO THE SECOND LINE SHOWN ABOVE!

If the user types "a; rm -f /some/file/here; locate a" as $searchString
it will delete the file (if Apache has permissions) and continue as if
nothing had happened....

Cheers,
Andy
Jul 17 '05 #4
"Andy Jeffries" <ne*****@seirffej.reverse.previous.word.co.uk> wrote in
message news:10***************@echo.uk.clara.net...
CountScubula wrote:
just a thought, but if its a linux platform you can try the locate command, and pass through grep for the parent directory:

// find all house pictures
$searchString = "house";
$files = `locate $searchString | grep '/www/parent/dir/pictures/'`;


Remember though that if the user is typing in $searchString - NEVER EVER
DO THE SECOND LINE SHOWN ABOVE!

If the user types "a; rm -f /some/file/here; locate a" as $searchString
it will delete the file (if Apache has permissions) and continue as if
nothing had happened....

Cheers,
Andy


True, but this was not meant to be a end all script snippet, however, I
should have seen that comming.

REVISED:

// find all house pictures
$searchString = "house";
$searchString = strtr($searchString,";./ ","----"); // andd chrs to remove,
as to keep safe
$files = `locate $searchString | grep '/www/parent/dir/pictures/'`;

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #5
CountScubula wrote:
// find all house pictures
$searchString = "house";
$files = `locate $searchString | grep '/www/parent/dir/pictures/'`;


Remember though that if the user is typing in $searchString - NEVER EVER
DO THE SECOND LINE SHOWN ABOVE!

If the user types "a; rm -f /some/file/here; locate a" as $searchString
it will delete the file (if Apache has permissions) and continue as if
nothing had happened....


True, but this was not meant to be a end all script snippet, however, I
should have seen that comming.


I know you knew that Mike (we've had technical chats a few times IIRC)
but I thought it prudent for anyone finding the post through Google or
maybe the OP.

Cheers,
Andy
Jul 17 '05 #6
"Andy Jeffries" <an**@seirffej.reverse.previous.word.co.uk> wrote in message
news:10****************@ersa.uk.clara.net...
CountScubula wrote:
// find all house pictures
$searchString = "house";
$files = `locate $searchString | grep '/www/parent/dir/pictures/'`;

Remember though that if the user is typing in $searchString - NEVER EVER
DO THE SECOND LINE SHOWN ABOVE!

If the user types "a; rm -f /some/file/here; locate a" as $searchString
it will delete the file (if Apache has permissions) and continue as if
nothing had happened....


True, but this was not meant to be a end all script snippet, however, I
should have seen that comming.


I know you knew that Mike (we've had technical chats a few times IIRC)
but I thought it prudent for anyone finding the post through Google or
maybe the OP.

Cheers,
Andy


Hi Andy, I didn't take any offense to it, I totally agree with you. Funny
thing is, someone posted a piece of code and asked what was wrong, and I
went to thier site, and brough it down several times (with thier permission)
and exploited several things, from just such a type of thing.

Thanks for keeping me on my toes. :)

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #7
Uzytkownik "Pedro Graca" <he****@hotpop.com> napisal w wiadomosci
news:c2*************@ID-203069.news.uni-berlin.de...
Also, will this bogg down the server.


I don't know. If it does maybe it's better to check for filename in a
filelist text file generated automaticcaly (by a cron job?)


Or cache the list and do a mtime comparison between the file and the
directory. It probably takes longer though for PHP to find an item in an
array then for the file system to locate a file, since there isn't function
that performs binary search.
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Carol | last post: by
5 posts views Thread by George | last post: by
6 posts views Thread by shantanu | last post: by
5 posts views Thread by Kaamp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.