473,569 Members | 2,866 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 11189
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
4082
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
66783
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
1783
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
1888
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
3126
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
11067
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
2079
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
1928
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
8139
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...
1
7684
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
7985
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
6298
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...
1
5515
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...
0
5234
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2120
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
1
1230
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
959
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.