Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 17th, 2007, 12:27 AM
Registered User
 
Join Date: Dec 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Warning: opendir(c: Inetpub vhosts

Hai Friends,
I'll make one music site. but i'll go to register page . the Error will be come . pls sugg.:(

Warning: opendir(c: Inetpub vhosts arullaudios.com httpdocs/avatars) [function.opendir]: failed to open dir: Invalid argument in c:\Inetpub\vhosts\xxxxxxxx.com\httpdocs\sources\av atars.php on line 110

Warning: readdir(): supplied argument is not a valid Directory resource in c:\Inetpub\vhosts\xxxxxxxx.com\httpdocs\sources\av atars.php on line 111

Script
<?php
/**
* This include displays a HTML list of all available avatars, allowing the user to select one.
*/

/**
* Recursive version of glob to suit versions from 4.0.6 to above.(glob is supported by 4.3.0 and higher versions of PHP).
* sthomas at townnews dot com
*
* @return array containing all pattern-matched files.
*
* @param string $sDir Directory to start with.
* @param string $sPattern Pattern to glob for.
* @param int $nFlags Flags sent to glob.
*/
function rglob($sDir, $sPattern, $nFlags = NULL)
{
$sDir = escapeshellcmd($sDir);
// Get the list of all matching files currently in the
// directory.

//$aFiles = glob("$sDir/$sPattern", $nFlags);
$aFiles = nglob($sDir, $nFlags);

// Then get a list of all directories in this directory, and
// run ourselves on the resulting array. This is the
// recursion step, which will not execute if there are no
// directories.

foreach (nglob($sDir.'/', "GLOB_ONLYDIR") as $sSubDir) // foreach (glob("$sDir/*", "GLOB_ONLYDIR") as $sSubDir)
{
// if(is_dir($sSubDir) && $sSubDir != '.' && $sSubDir != '..')
    if(is_dir($sSubDir))
     {
        $aSubFiles = rglob($sSubDir, $sPattern, $nFlags);
        $aFiles = array_merge($aFiles, $aSubFiles);
     }

}
/**/
// The array we return contains the files we found, and the
// files all of our children found.
/************************************************** *****/
for($vloop=0;$vloop<count($aFiles);$vloop++)
    {
        $vvfiles[] = $sDir.$aFiles[$vloop];
    }


    return $vvfiles;
/************************************************** ******/
// return $aFiles;
}

/* Get Listing of avatars */
if (is_dir(AVATAR_DIR.AVATARS_DIR_STOCK))
    $files = rglob (AVATAR_DIR.AVATARS_DIR_STOCK, '*');
else
    $files = array();

#sorting won't solve your '.' and '..' problem.
#sort ($files, SORT_STRING);

/**
* Display table of images
*/

echo '<table>';
# you can't start off with 0. that will add a extra one to the line.
$x = 1;
# looping files does not need a for loop. also for loops result in
# weird indexing and skipped indexes in some cases. use ofreach to
# cycle in cases like this.
foreach ($files as $avatar) {
# one means starting row.
if ($x == 1) {
echo '<tr>';
}
# strip out path.
$avatar = substr($avatar, strlen(AVATARS_DIR));
# show input and image.
echo '<td>';
echo '<input type="radio" name="avatar" value="'.$avatar.'" '.($form->value("avatar") == $avatar ? 'checked' : '').' onClick="document.getElementById(\'avatar_type_cho ose\').checked=1">';
echo '<img src="avatars/'.$avatar.'" width="30" height="30" alt="'.$avatar.'" align="middle">';
echo '</td>';
# last column, row end.
if ($x == AVATARS_PER_ROW) {
echo '</tr>';
#restart loop, becomes 1 in next line on $x++ crank.
$x = 0;
}
$x++;
}
# did you exit cleanly from the loop?
# $x = 0; is in the AVATARS_PER_ROW then $x++; is done.
# this results in a 1 result on clean looping.
if ($x != 1) {
# till we are at the last column keep going.
while ($x != AVATARS_PER_ROW) {
echo '<td></td>';
$x++;
}
# we are clean now, end the row.
echo '</tr>';
}
echo '</table>';


function nglob($sDir,$nFlags="") {
$handle = opendir($sDir);
while (false !== ($file = readdir($handle))) {
# on *nix the first files are '.' and '..' but you're on a windows server.
# windows does not put '.' and '..' first so you can NOT delete
# the first 2 indexes in a array and be ok.
# to do this the proper way you look for '.' and '..' as a value.
# these will never be file names so a is_dir() check is trivial/pointless.
if ($file != '.' && $file != '..') {
    $files[] = $file;
}
}
closedir($handle);
return $files;
}
?>





Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP no longer compiling (inetpub folder problem?) rayburn Beginning PHP 3 January 10th, 2008 02:04 PM
Access to the path "C:\Inetpub\wwwroot\wrox\ThePhi renodays BOOK: ASP.NET Website Programming Problem-Design-Solution 6 August 3rd, 2007 06:21 PM
Accessing C:\Inetpub\wwwroot on networked machine RussellT Dreamweaver (all versions) 7 March 5th, 2006 08:58 AM
Store ASP.NET files in other than C:\Inetpub RNedel ASP.NET 1.0 and 1.1 Basics 2 September 23rd, 2003 05:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.