Jump to content

tigertim

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male
  • Location
    UK

tigertim's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, I'm afraid I didn't know how to insert the bug tracking script, I just get the following syntax error if i cut and paste it into the code. I'm a real beginner to php so please bear with me! Parse error: syntax error, unexpected $end in /c/website/count.php on line 49 I think i can see what its doing though but i don't know why. The actual total of folder "A" has 35 fies (I counted them manually) the script shows 33 files and 2 folders, when there aren't any folders in the A folder and all the file types are the same. Any ideas why it doing this? Thanks
  2. Awesome, thanks very much for your reply, however, it doesn't seem to been totalling the correct number of files in the folder, below is the code that you (with the path) re did for me but in the eg i did it counts 33 files when there are actually 35 (with no subfolders), any ideas why? <?php function directoryCount($directory, $recursive=false) { $objects = glob($directory.'/*'); if($objects === false) { user_error(__FUNCTION__."(): Invalid directory ($directory)"); return false; } $fileCount = 0; $folderCount = 0; foreach($objects as $object) { (is_file($object)) ? $fileCount++ : $folderCount++; if($recursive) { $subFolderCount = directoryCount($object, $recursive); $fileCount += $subFolderCount->files; $folderCount += $subFolderCount->folders; } } $output->files = $fileCount; $output->folders = $folderCount; $output->total = ($fileCount+$folderCount); return $output; } $folderCount = directoryCount('../media/Images/A', true); if($folderCount === false) { echo "<p>Oops....something went wrong.</p>\n"; } else { echo "<p>There are {$folderCount->files} images beginning with the letter A. </p>\n"; // That is a total of {$folderCount->total} -- and {$folderCount->folders} folders -- } ?>
  3. Hi, thanks very much for your quick reply and whilst I'm sure to someone with a good understanding of php it's all that's needed, however I'm a real beginner, could you (or someone) explain exactly how I'd go about calling the function again please. Many thanks in advance
  4. Perfect! That's exactly what i was trying to do, thanks very much for you help!
  5. Hi I'm working with the following code to count the number of files in a directory, however, it doesn't seem to count files in subdirectories, does anyone have any ideas how I can get it to? Thanks! The code so far is as follows: <?php function numFilesInDir($directory, $includeDirs = false) { $files = glob($directory.'/*'); if($files === false) { user_error(__FUNCTION__."(): Invalid directory ($directory)"); return false; } $numFiles = count($files); if(!$includeDirs) //remove ! to count folders instead of files { $dirs = glob($directory.'/*', GLOB_ONLYDIR); $numFiles = $numFiles - count($dirs); } return $numFiles; } $numFiles = numFilesInDir('../media/Images'); if($numFiles === false) { echo "<p>Oops....something went wrong.</p>\n"; } else { echo "<p>There are $numFiles pictures in the Image folder.</p>\n"; } ?>
  6. Hi Sorry if this is the wrong place for this but I'm totally stumped here and I know its a basic question but I'm very new to php and I need help :-) Basically all i would like to do is hide certain file types, folders (specifically the folder .AppleDouble) and hidden files, below is my code so far and I'd really appreciate it if anyone could help me out by taking a look! Any help would be very gratefully received! Here's my code so far: <? $rootdir = "../media/Documents"; function printdir($dir) { $dircount = 0; $filecount = 0; $handle = opendir($dir); while (false != ($file = readdir($handle))) { if (@filetype($dir . "/" . $file) == "dir" AND $file != "." AND $file != "..") { $dirlist[$dircount] = $file; $dircount++; } else { if (strtolower(substr($file, -4)) == ".avi") { $filelist[$filecount] = substr($file, 0, (strlen($file)-4)); $filecount++; } } } closedir($handle); if ($dircount>0) {sort ($dirlist);} if ($filecount>0) {sort ($filelist);} for ($i = 0; $i < $dircount; $i++) { echo "<dl>\n"; echo "<dt><B>" . $dirlist[$i] . "</B></dt>\n"; flush(); printdir($dir . "/" . $dirlist[$i]); echo "</dl>\n\n"; } for ($i = 0; $i < $filecount; $i++) { echo "<dd>" . $filelist[$i] . "</dd>\n"; flush(); } if ($filecount + $dircount == 0) { echo "<dd><i><empty folder></i></dd>\n"; } } printdir($rootdir); ?>
  7. Awesome!!! Thanks very much guys for your help, I've learn alot and everything works, thanks again
  8. Hi Sorry if this is the wrong place for this but I'm totally stumped here and I know its a basic question but I'm very new to php and I need help :-) Basically all i would like to do is list the files and folders in the following directory alphabetically, I know i need to put them in an array etc but I don't know how and would really appreciate some help! So any help would be very gratefully received. Here's my code so far: <?php $sub = ($_GET['dir']); if (strstr($sub, "..")) {$sub = "";} $path = '../media/Documents'; $path = $path . "$sub"; $dh = opendir($path); $i=1; while (($file = readdir($dh)) !== false) { if(substr($file,0,1) != ".") { if (substr($file, -4, -3) =="."){ echo "<font size=2 face=\"Arial, Helvetica, sans-serif\">$i. $file <br />"; }else{ echo "<font size=2 face=\"Arial, Helvetica, sans-serif\">$i. <a href='?dir=$sub/$file'>$file</a><br />"; } $i++; } } closedir($dh); ?> Many thanks in advance!
  9. Thanks very much for quick reply! As I said I'm pretty new to PHP so please bear with me. Taking your advice, should the code therefore look like this (I'm guessing not as it doesn't seem to work) :'( : -------------------------- <?php $sub = ($_GET['dir']); if (strstr($sub, "..")) {$sub = "";} $path = '../media/Movies'; $path = $path . "$sub"; $dh = glob($path); array = sort(a,z) $i=1; while (($file = readdir($dh)) !== false) { if(substr($file,0,1) != ".") { if (substr($file, -4, -3) =="."){ echo "<font size=2 face=\"Arial, Helvetica, sans-serif\">$i. $file <br />"; }else{ echo "<font size=2 face=\"Arial, Helvetica, sans-serif\">$i. <a href='?dir=$sub/$file'>$file</a><br />"; } $i++; } } closedir($dh); ?> --------------------------
  10. I'm pretty new to php and I'm furiously trying to get this code to list the folders/files alphabetically but to no avail! I'd really appreciate it if someone could take a look and guide me as to what to do, I'm pulling what little hair i have left out! I can currently see the folder contents but the order is all over the place. Thanks very much!!! -------------------------- <?php $sub = ($_GET['dir']); if (strstr($sub, "..")) {$sub = "";} $path = '../media/Movies'; $path = $path . "$sub"; $dh = opendir($path); $i=1; while (($file = readdir($dh)) !== false) { if(substr($file,0,1) != ".") { if (substr($file, -4, -3) =="."){ echo "<font size=2 face=\"Arial, Helvetica, sans-serif\">$i. $file <br />"; }else{ echo "<font size=2 face=\"Arial, Helvetica, sans-serif\">$i. <a href='?dir=$sub/$file'>$file</a><br />"; } $i++; } } closedir($dh); ?> --------------------------
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.