473,587 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to browse a directory for a file?

Hi,

I need to add a download function in a VB program, but since a file
can be located anywhere in our /download section on the web, I was
thinking of putting a PHP script there that would take the filename as
parameter, and browse through the /download directory to look for this
file, including sub-directories, and return the URL, ie.

IN
http://www.acme.com/download/find.php?file=myfile.txt

OUT
www.acme.com.com/download/sub1/myfile.txt

Does anyone have working code to achieve this?

Thank you
JD.
Jul 17 '05 #1
6 11192
Jane Doe wrote:

Hi,

I need to add a download function in a VB program, but since a file
can be located anywhere in our /download section on the web, I was
thinking of putting a PHP script there that would take the filename as
parameter, and browse through the /download directory to look for this
file, including sub-directories, and return the URL, ie.

IN
http://www.acme.com/download/find.php?file=myfile.txt

OUT
www.acme.com.com/download/sub1/myfile.txt

Does anyone have working code to achieve this?


You could probably use exec and the linux "find" command to do this.

Or, you could make a recursive function that reads files of a directory using
opendir, readdir, closedir and compares the filename to the one requested using
preg_match. If it encounters a directory (is_dir) you could call the same
function to traverse it. Caution: be careful not to traverse "..". Also, make
sure that the user can't steal files from outside the download directory

http://www.acme.com/download/find.php?file=/etc/passwd
or
http://www.acme.com/download/find.ph...ris_hilton.mov

This is actually a pretty easy function to write.

Regards,
Shawn
--
Shawn Wilson
sh***@glassgian t.com
http://www.glassgiant.com

I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.
Jul 17 '05 #2
On Tue, 13 Jan 2004 13:14:26 -0400, Shawn Wilson wrote:

I was doing something similar to this, and ended up smashing my head
against the wall for hours, and all because I had forgotten to ensure that
the case of the filename was correct.

Grrr! Why can't you find 'XmasCard.jpg'? It's right there! Smack!
Grrrr!
(repeat ad cranium-fracture)

Later....

oh, hang on a minute.... what if I use 'strtolower'?

Honey, I think I got it working! Are there any head bandages in the
house?
Just thought I'd share that, to save you any concussions..

Jul 17 '05 #3
adamt wrote:

On Tue, 13 Jan 2004 13:14:26 -0400, Shawn Wilson wrote:

I was doing something similar to this, and ended up smashing my head
against the wall for hours, and all because I had forgotten to ensure that
the case of the filename was correct.

Grrr! Why can't you find 'XmasCard.jpg'? It's right there! Smack!
Grrrr!
(repeat ad cranium-fracture)

Later....

oh, hang on a minute.... what if I use 'strtolower'?

Honey, I think I got it working! Are there any head bandages in the
house?

Just thought I'd share that, to save you any concussions..


Ah, yes. You can also use something like:

preg_match("/something/i", $var);

The "i" after the last delimiter denotes case-insensitive search.

Regards,
Shawn

--
Shawn Wilson
sh***@glassgian t.com
http://www.glassgiant.com

I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.
Jul 17 '05 #4
Shawn Wilson wrote:

Jane Doe wrote:

Hi,

I need to add a download function in a VB program, but since a file
can be located anywhere in our /download section on the web, I was
thinking of putting a PHP script there that would take the filename as
parameter, and browse through the /download directory to look for this
file, including sub-directories, and return the URL, ie.

IN
http://www.acme.com/download/find.php?file=myfile.txt

OUT
www.acme.com.com/download/sub1/myfile.txt

Does anyone have working code to achieve this?


You could probably use exec and the linux "find" command to do this.

Or, you could make a recursive function that reads files of a directory using
opendir, readdir, closedir and compares the filename to the one requested using
preg_match. If it encounters a directory (is_dir) you could call the same
function to traverse it. Caution: be careful not to traverse "..". Also, make
sure that the user can't steal files from outside the download directory

http://www.acme.com/download/find.php?file=/etc/passwd
or
http://www.acme.com/download/find.ph...ris_hilton.mov

This is actually a pretty easy function to write.


Oh, I forgot to mention that this function could return more than one result or
it could just return the first instance of the filename. You have to consider
how you want it to handle that. For that matter, the linux 'find' command could
return more than one result as well.

Regards,
Shawn
--
Shawn Wilson
sh***@glassgian t.com
http://www.glassgiant.com

I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.
Jul 17 '05 #5
Also, watch out the symbolic links so the function won't don't end up
calling itself ad infinitum.

Uzytkownik "Shawn Wilson" <sh***@glassgia nt.com> napisal w wiadomosci
news:40******** *******@glassgi ant.com...
Or, you could make a recursive function that reads files of a directory using opendir, readdir, closedir and compares the filename to the one requested using preg_match. If it encounters a directory (is_dir) you could call the same
function to traverse it. Caution: be careful not to traverse "..". Also, make sure that the user can't steal files from outside the download directory

http://www.acme.com/download/find.php?file=/etc/passwd
or
http://www.acme.com/download/find.ph...ris_hilton.mov

This is actually a pretty easy function to write.

Regards,
Shawn
--
Shawn Wilson
sh***@glassgian t.com
http://www.glassgiant.com

I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.

Jul 17 '05 #6
On Tue, 13 Jan 2004 20:05:42 -0500, "Chung Leong"
<ch***********@ hotmail.com> wrote:
Also, watch out the symbolic links so the function won't don't end up
calling itself ad infinitum.


Thx everyone :-)

JD.
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4084
by: mscir | last post by:
I just installed ASP after a couple of years of not using it, PWS Win 98 SE. A couple of things are throwing me, and I can't remember whether these worked in the past. One is I can't double-click on an .asp file in my file explorer and have it load in IE6. IE shows the page in the address bar, e.g. C:\Inetpub\wwwroot\myweb\math.asp
21
66793
by: strutsng | last post by:
<input type="file"> only allows the user to browse for files. How about "browse for folder" dialog? Can html/javascript do that? I couldn't find any syntax for that. If not, please advise what are the other approaches. please advise. thanks!!
5
1784
by: Eric Twietmeyer | last post by:
Hi, Does anyone know why starting with VS.NET 2002 (and same with 2003) it is no longer possible to browse to a directory that has "ept" as part of the path? It worked fine in Vc 6.x. My initials and user name happen to be "ept", and so I have directories with that name. It is no longer possible to browse to any subfolder and therefore...
4
1889
by: Larry Brindise | last post by:
I have an asp.net application. I have used VStudio Web Deployment Project to create the MSI file. I copy the MSI file from my developer PC to my test server running Win2003Server Web Edition. I run the MSI to install - looks good so far - I see the global directory, etc. I try opening the app in IE via www.myweb.com/aspxfolder; where...
5
3128
by: Mike Moore | last post by:
I need to create something very similiar to the browse folder capability. This would allow me to support the following - A user would create a document on their server, then they would need to login to the application which we are building to 1). the user would locate their purchase request record in the application. 2). browse the...
3
11069
by: Highlander | last post by:
Hello all. Consider the following HTA: <HTML> <HEAD> <TITLE></TITLE></HEAD> <BODY> <SCRIPT LANGUAGE="VBScript"> Sub ButBrowse_onclick() '-- show browse window and Get file path:
7
2080
by: nicknack | last post by:
Hello. I would like to give my user an option to find a directory and choose it. Its just like the FileUpload control but the fileupload control choose only files (if you choose a directory and press enter it open it and not choose it). is there a way to do it?
0
1930
by: William Gill | last post by:
I am trying to convert a Python App I wrote that generates html docs from a template. It comes in handy when doing things like photo galleries where dozens of pages are identical except the previous link, next link, and current image. I don't believe in dynamically generating pages where the query can be anticipated, and static pages will do....
0
7915
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...
0
7843
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...
0
8205
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. ...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
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...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.