PHP - Odd Bahaviour With Opendir And Readdir
Hi folks,
First time posting here and a bit of a novice at PHP, but am learning.... I am fiddling with a small bit of code to create a very basic php gallery (I'm sure everyone has at some point). I started off with a mysql intergrated one then thought I would try a new one without the mysql. Its working fine but I am just having one very strange problem. Basically, I started of with just /mygallery/index.php?w=... where ... = the location (physical folder) of photos. I use opendir to open the contents of w= and parse whether it is a directory or a file (then narrow it down to just images). If it is a dir, then I present it as a link to that folder (sub-album) if it is a photo, I present a thumb link to the image. Now I have added a mod_rewrite rule to allow my urls to be of the form 'mygallery/album/subalbum' this gets ocnverted into 'mygallery/index.php?w=album/subalbum' Now the funny bit. If I create a new folder in one of the subalbum, e.g. : mygallery/album/subalbum/<b>New Folder</b> the code works. i.e. when I point my browser at 'mygallery/album/subalbum' I get a link showing 'New Folder' But if I create a new folder of any other NAME it does not appear in the list!! So if I just rename 'New Folder' to 'New Folde' it drops of the web page!!! Now I am really not sure what the hell is going on... Hope someone can help. I will post my code if necessary. Thanks in advance! Jon Reynolds Similar TutorialsI've had a bit of a search around to see if this is possible but have yet to find something. I'm looking to be able to offset the results from opendir or similar function without returning all the files/folders. In other words i'd like to display the file/folder results over multiple pages when there are a lot of files/folders to display. Is this at all possible? Hi, I need to read files from a web directory. I have tested the "opendir" function but it doesn't work. <?php if ($handle = opendir('http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV')) { echo "Directory handle: $handle\n"; echo "Files:\n"; /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { echo "$file\n"; } /* This is the WRONG way to loop over the directory. */ while ($file = readdir($handle)) { echo "$file\n"; } closedir($handle); } ?> How can I read files from a directory like this? Best Regards, Hi everyone, I'm building a website for a music band and want to automate the adding of new album/disc so they wont have to update a php file to print out . I mean, a new album is release , then dump the mp3's, lyrics, cover pics in their respective directory using naming convention so my php read the directory structure and so one... but my problem is the php function opendir read the filesystem... is there a more secure way to do this ? and I presume the web host wont let me do this... thanks for any tips and tricks steph Sorry for the noobie question, I am just a beginner still. I am trying to use the readdir function to echo back all the contents of a folder. The directory that I want to read back has 31 empty folders. I am able to get them to read back, but they are in a random order and there are two additional files at the top named "." and ".." -- any idea how to fix these? Here is my code and pictures: Quote $path = "c:/test/"; if(is_dir($path)) { if($dir_handle = opendir($path)) { while($filename = readdir($dir_handle)) { echo "filename: {$filename}<br>"; } closedir($dir_handle); } } Hey guys basically with a simple script that I made I need some help with it's doing my head in. What i'm trying to do is allow multiple filetypes to be shown by readdir, i want both .zip and .rar to be in the list, not just .zip how would i add .rar in this method as well to be visible on readdir? <?php $dirname = "/home/test/"; $dir = opendir($dirname); $extension = array_pop(explode(".", $file)); ?> <?php while(false != ($file = readdir($dir))) { if ($file != "." && $file != ".." && array_pop(explode(".", $file)) == "zip") { echo(" <b>» <a href='$dirname$file'>$file - Download</a> <br /> </b> "); } } ?> Hi all, I have a PHP function that reads JPG's from a folder that contains over 100,000 files. The problem I have is that the READDIR() function takes a while to list the contents due to the large number of files. I'm trying to speed up the process by using a filter and listing only the files I need. Example: list files with a timestamp for an entered date period. Code: [Select] $file >= '2012-04-02 OR $file <= '2012-03-04' This lists the JPG files but my modification to list files using a timestamp does not work nor can I find a way of seeing why it does not work. This has me stuck. Thank you in advance to anyone who can post some pointers. Code that lists JPGS only Code: [Select] <?php $path = 'imgs/'; function directory($dir,$filters) { $handle=opendir($dir); $files=array(); if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}} // 'all' filter is if you set to list ALL files and folders. if ($filters != "all") { $filters=explode(",",$filters); while (($file = readdir($handle))!==false) { for ($f=0; $f < sizeof($filters); $f++): $system=explode(".",$file); if ($system[1] == $filters[$f]){$files[] = $file;} endfor; } } closedir($handle); return $files; } $files = directory($path, "jpg"); //for multiple file types just separate the file extensions by commas foreach ($files as $value) { echo $value.'<br>'; } ?> I have added the filter Code: [Select] && filemtime($file) >= strtotime('2010-04-12') but it does not work. Code: [Select] <?php $path = 'imgs/'; function directory($dir,$filters) { $handle=opendir($dir); $files=array(); if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}} // 'all' filter is if you set to list ALL files and folders. if ($filters != "all") { $filters=explode(",",$filters); while (($file = readdir($handle) && filemtime($file) >= strtotime('2010-04-12'))!==false) { for ($f=0; $f < sizeof($filters); $f++): $system=explode(".",$file); if ($system[1] == $filters[$f]){$files[] = $file;} endfor; } } closedir($handle); return $files; } $files = directory($path, "jpg"); //for multiple file types just separate the file extensions by commas foreach ($files as $value) { echo $value.'<br>'; } ?> Hi all I hope I have come to the right place. My system reads files stored on a drive and lists them to users through plain HTML, I made it 11 years ago and have to refresh my memory. My problem is that filenames seem to come in different formats, to how to decode/encode them is an issue...
My users use Scandinavian letters (æøåäöüõ) and it seems like one filename is in one format and another in another format. There is no logic to what format the filenames comes it. All files are ok and downloads as they should, they just dont list well. Any idea how I can handle this issue?
My new host (Siteground) cloned and moved my html/php site (built by the previous owner) from Heart Internet server. All of the site works except for the sidebar, I get these 2 errors. Anyone shed any light on these at all?
Warning: readdir(): supplied argument is not a valid Directory resource in /home/customer/www/dunster.org.uk/public_html/include/toolbox.php on line 97
Warning: opendir(/home/sites/dunster.org.uk/public_html//local_information) [function.opendir]: failed to open dir: No such file or directory in /home/customer/www/dunster.org.uk/public_html/include/toolbox.php on line 86 |