473,405 Members | 2,279 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,405 software developers and data experts.

Using URL in opendir() as absolute path

Hello,

I would like to use an URL insttead of a local path in the following command, is it possible?

Expand|Select|Wrap|Line Numbers
  1. $url = 'http://www.mysite.com/content/';
  2. $dir = opendir($url);
  3.  
Thank you,

kkhan
Jul 10 '08 #1
2 5103
chazzy69
196 100+
I don't know about that function but you can use fopen to open a file with a url, also you mabye be able to use an include statement depending on what your trying to achieve.
Jul 11 '08 #2
Thank you chazzy69. Here is the php code I am working. This lists and display files from a certain folder. I would like to use this code as an include for several directories, however, it always want to look for $dirpath below the current folder. I hope that a fixed url will fix this problem, but I am not sure whether opendir function can use urls instead of local paths.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dirpath = "content";
  3. $dh = opendir($dirpath);
  4. while (false !== ($file = readdir($dh))) {
  5. $fileList[] = trim($file);
  6.  
  7. //Don't list subdirectories
  8. if (!is_dir("$dirpath/$file")){
  9. sort ($fileList); // sort the file list in the array
  10. }
  11. }
  12. reset ($fileList); // go back to the top of the array
  13. while (list ($key, $file) = each ($fileList))
  14. {
  15. //Truncate the file extension and capitalize the first letter
  16. echo "<a href='$dirpath/$file'>". htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))). "<br />";"</a>";
  17.  
  18.  
  19. }
  20. closedir($dh); 
  21. ?>
  22.  
Jul 11 '08 #3

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

Similar topics

14
by: Bruce A. Julseth | last post by:
When I execute this SQL statement in my PHP code, I get an error "File '.\Address.txt' not found (Errcode: 2)" $File = addslashes(".\Address.txt"); $SQL = "Load Data InFile \"" . $File . "\"...
4
by: dchaffin | last post by:
I'm having a problem using file_exists with an absolute path and I can not figure out why. I tried the exact example that is on www.php.net ... <?php $filename = '/path/to/foo.txt'; if...
1
by: Bob Gervais | last post by:
Hi, I am writing a very simple script that should return all subdirectories on a given path (non recursively, so just first level). This is the sub that I have for doing this but it gives very...
2
by: Alex | last post by:
Greetings all, I'm trying to use the "opendir" command on Win32 in a CGI script. I'm using Apache 2.0.48 for Win32. The "openDir" command works from the CGI script when I try to open a...
4
by: gnah | last post by:
Greetings, I hope my problem is easy to fix, I'm pretty new with php - but I am getting weird results with the opendir() function. It may just be a path problem, but I don't see which variable...
4
by: FayeC | last post by:
I have tried to use a php code (found it online) to create a gallery but I am wondering if thereare any other PHP options besides using EXIF. The reason is that the images I am using for the...
6
by: Jon Slaughter | last post by:
do I have to prefix every absolute path with document root to get it to work? For some reason I thought that prefixing a path with '/' or './' with make it absolute w.r.t to document root but I...
7
code green
by: code green | last post by:
I am trying to access files on a different drive but the same server to where the script is running. but I only get the error failed to open dir: Invalid argument in...
6
by: MK | last post by:
I don't use c much but i've done lots of perl, perl/Tk, and shellcode on LINUX. I'm trying to do things with directory trees and i occasionally get back an errno from opendir "No such file or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...
0
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...
0
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,...

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.