473,386 Members | 1,710 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,386 software developers and data experts.

Get folder name

How can I get all folder names from a specific directory and list them using PHP?
Jan 21 '08 #1
8 17058
stepterr
157 100+
How can I get all folder names from a specific directory and list them using PHP?
Check out the scandir function. This should help you out.
Jan 21 '08 #2
Check out the scandir function. This should help you out.
It didn't work. i received a "call to undefined function" error. is this has something to do with my PHP version? I'm using PHP 4
Jan 22 '08 #3
svenni
4
scandir is PHP5, so to do the same in PHP4 you would need a different approach, which means a couple more lines of code.

I've done this some time ago, but I couldn't find my own code at the moment, so I found a similar code here :
[PHP]
<?php
// declare the folder
$ourDir = "/home/public_html/folderName";

// prepare to read directory contents
$ourDirList = @opendir($ourDir);

// loop through the items
while ($ourItem = readdir($ourDirList))
{
// check if it is a directory
if (is_dir($ourItem))
{
echo "directory: $ourItem <br />";
}
// check to see if it is a file
if (is_file($ourItem))
{
echo "file: $ourItem <br />";
}
}

closedir($ourDirList);
?>
[/PHP]
This should work in PHP4 as well as PHP5.
Jan 22 '08 #4
stepterr
157 100+
Yep, svenni is correct that is a PHP 5 function. Svenni's method should work for what you want. If you want to see more directory functions, check out this site
Jan 22 '08 #5
That is exactly what I'm trying to get. thanks guys! By the way do you any ways of searching a file from a specific directory? including its subdirectories? and display a list of search results. As of now I'm thinking of using a database for that but I'm still hoping for a better alternative
Jan 24 '08 #6
svenni
4
That is exactly what I'm trying to get. thanks guys! By the way do you any ways of searching a file from a specific directory? including its subdirectories? and display a list of search results. As of now I'm thinking of using a database for that but I'm still hoping for a better alternative
I think listing all the files in a database might be a good idea, but it depends on the amount of files. It shouldn't be a big problem for PHP to loop through lets say 100 files and return the ones which match your criteria, but if you have more than 1000 files I guess it would be best to use the indexing features in MySQL to search faster. The problem would though be the fact that the database needs to be updated once in a while, and I'm not quite sure about how often.

Anyways, good luck!
Jan 28 '08 #7
I could use some help with almost something similar:


I am trying to get php to read the folder name that php is in and write it to a text file.

i.e. www.mydomain.com/john

I need the script to write john to a text file

although this will not work; something close:

<?php

$_SERVER["REQUEST_URI"]
$your_data =($_SERVER);

// Open the file and erase the contents if any

$fp = fopen("textfile_name.txt", "w");

// Write the data to the file
fwrite($fp, $your_data);

// Close the file
fclose($fp);

?>




The overall all goal is to also perform the following if possible using php.



when it write the folder name:

the folder named one of the two ways:

/bob
/mary-jane

can it upppercase to Bob
can it upper case to Mary Jane and drop the -


anyone have any ideas?


The end result is flash to read the txt file and so it can write it into the flash sction script.


The part I am not sure is after php writes it to the text file, will it happen before flash reads the txt file?



Thanks for any assistance


LL
Jun 20 '08 #8
i've done that job with the code, which gets and outputs the file path:

<?php
$Path=$_SERVER['REQUEST_URI'];
$URI='http://www.example.com'.$Path;

echo "$URI";
?>
Feb 10 '12 #9

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

Similar topics

1
by: New User | last post by:
asp.net framework 1.1 and c# I am trying to create thumbnail images dynamically and load them on a web page. When I click on a thumbnail image it opens the large version of it. I use DataList...
1
by: New User | last post by:
asp.net framework 1.1, C# I am trying to create thumbnail images dynamically and load them on a web page. When I click on a thumbnail image it opens the large version of it. I use DataList to...
1
by: Brent | last post by:
This one should be pretty easy, but I just can't figure it out. I am receiving a folder path into a string variable. I need to remove the folder name after the last slash. What is the easiest...
5
by: _DG | last post by:
At least when you've got any docs in .CHM format in the folder tree. If you drop a file called CSharpDocs.chm into a folder: \toplevel\C#\docs, you can open it, but it won't display. The #...
6
by: jodyblau | last post by:
I am using the following code to open a folder: Dim folderstring As String Dim rs1 As DAO.Recordset Set rs1 = CurrentDb.OpenRecordset("Select * from tblMisc_Settings where Description =...
2
by: walter | last post by:
Hi there, I store all my images in the theme folder so that it can be changed. The problem is that I need to use <img> to access these images , but I don't want to lose the theme capability. So is...
0
by: Alex | last post by:
Hi, I made a deployment package that needs to install its files to a folder which name contains a single quote (it's in french). I changed the Application folder's default location to point to...
11
by: =?Utf-8?B?UGF1bA==?= | last post by:
I did a google search but could find what I was looking for. I am creating a temporary folder and placing files in it with a web application. The temporary folder name needs to be changed...
4
by: mail2sanand | last post by:
Hi All, I am trying to create a folder with "&" in itz name (Ex: TS_&_ABC) with the help of perl's ssh command in another server. The exact command I am triggering in the code is ...
6
by: madlan | last post by:
Hi, How would I retrive the folder name a file is in? In this example I just want the highlighted folder name: C:\Program Files\FolderNameIWant\Application.exe I can get the path excluding...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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.