Help with readdir()

Hello,
I am hoping somone here can help me out. I recently changed the server my website was on and now my .php script is not working properly.
Here is the error message I am getting:
Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/evergree/public_html/admin/add_image.php on line 53
Whick I believe in turn is causing this error: Warning: Invalid argument supplied for foreach() in /home/evergree/public_html/admin/add_image.php on line 105

Here is the script I am using to try and read the files and directories to list them out on the page: [code]$today = date(“Y-m-d”);
$myID = $_GET[‘specialID’];
$myURL = $_POST[‘imgURL’];
$myCAT = $_GET[‘category’];
$editFormAction = $_SERVER[‘PHP_SELF’];
if (isset($_SERVER[‘QUERY_STRING’])) {
$editFormAction .= “?” . htmlentities($_SERVER[‘QUERY_STRING’]);
}

if ((isset($_POST[“MM_insert”])) && ($_POST[“MM_insert”] == “form1”)) {
$insertSQL = “UPDATE web_specials SET imgURL=’$myURL’ WHERE web_specials.title=’$myID’”;
//UPDATE web_specials SET imgURL = ‘testing/url’ WHERE web_specials.title = ‘test’
mysql_select_db($database_specials, $specials);
$Result1 = mysql_query($insertSQL, $specials) or die(mysql_error());

$insertGoTo = ‘specials_select.php’;
if (isset($_SERVER[‘QUERY_STRING’])) {
$insertGoTo .= (strpos($insertGoTo, ‘?’)) ? “&” : “?”;
$insertGoTo .= $_SERVER[‘QUERY_STRING’];
}
header(sprintf(“Location: %s”, $insertGoTo));
}
/SCRIPT TO LIST IMAGE FILES ALPHABETICALLY/

$path = “…/specials/images/$myCAT”;
$dh = @opendir($path);

while (false !== ([email protected]($dh)))
{
if (substr($file,0,1)!=".")
{
if (is_dir($file))
$dirs[]=$file.’/’;
else
$files[]=$file;
}
}
@closedir($dh);

if ($files)
natcasesort($files);
if ($dirs)
natcasesort($dirs);

$files=array_merge($dirs,$files);[/code]

Have you tried debugging (see my signature), like print_r($dirs)? Make sure $dirs is an array.

if there are no directories, then dirs[] never gets initialized and thus is never defined as an array. This will cause the array_merge to error.

Sponsor our Newsletter | Privacy Policy | Terms of Service