Click to See Complete Forum and Search --> : problem with windows server :-(


Johno M
04-30-2005, 02:30 PM
I'v been messing around with scripts from online for days, trying to get them to work on my windows hosted webspace but they dont. A friend put them on his webspace (linux i think) and they worked.

This is a script from online, this is the index page, its for a news thing.

<?php

$display = 10;

if ( $handle = opendir("news/") )
{
while ( ( $file = readdir( $handle ) ) !== false )
{
if ( $file != "." && $file != ".." )
{
$news_array[] = $file;
}
}
closedir( $handle );
}

array_multisort( $news_array, SORT_NUMERIC, SORT_DESC );
array_splice( $news_array, $display );

$num_news = ( count( $news_array ) );

foreach ( $news_array as $val )
{
$news_file = file("news/$val");

$title = $news_file[1];
$date = $news_file[0];
$text = $news_file[2];

echo '<center><table width="98%"><tr><td align="left" class="news"><p align="left"><font size="3">'.$title.'</font><font size="2"><i>'.$date.'</i>';
echo '</font></td></tr>';
echo '<table width="98%"><tr><td align="left" class="news"><p><font size="2">'.$text.'</font></td></tr></table>';
echo '<br>';
echo '<p>Powered by <a href="http://timurkz.buildtolearn.net">KZ Server</a><br>';
}
?>

<!--And the button for admin page-->
<a href="admin.php" class="mirror"><font size="1">Admin</font></a>

------------------------------------------------------

When I run it, i get this:

Warning: opendir(news/) [function.opendir.php]: failed to open dir: Invalid argument in <------------my webspace--------------------> on line 61

Warning: array_multisort() [function.array-multisort.php]: Argument #1 is expected to be an array or a sort flag in <------------my webspace--------------------> on line 73

Warning: array_splice() [function.array-splice.php]: The first argument should be an array in <------------my webspace--------------------> on line 74

Warning: Invalid argument supplied for foreach() in <------------my webspace--------------------> on line 78
Admin

---------------------------------------------------------

Any ideas?

Johno M
04-30-2005, 09:35 PM
ooooh come on! 52 views, no ideas? :-D

I THINK, i dont know, but I think it has summin to do with the fact its a windows operating system on the web space.

bradgrafelman
04-30-2005, 11:08 PM
Obviously, we can trace all of your errors (at present) back to the failed opendir() call; it can't even open the directory, let alone process the data.

Perhaps the include path is not set correctly, perhaps Windows just wants to encourage you to become less lazy in your coding; who knows.

Try using a FULL PATH in your opendir(). An example would be:

$path = $_SERVER['DOCUMENT_ROOT'] . 'news/';
if(!is_dir($path)) die('Error: <b>'.$path.'</b> is an invalid directory.');
if ( $handle = opendir($path) )
// ...

etc. Try using that and tell us what happens.

Johno M
05-01-2005, 09:46 AM
Ok, i dont know a thing about php, where do I put that in the code, and do I have to alter it?

bradgrafelman
05-01-2005, 12:58 PM
At the top, you have this:

<?php

$display = 10;

if ( $handle = opendir("news/") )
{

Change that to this:

<?php

$display = 10;

$path = $_SERVER['DOCUMENT_ROOT'] . 'news/';
if(!is_dir($path)) die('Error: <b>'.$path.'</b> is an invalid directory.');

if ( $handle = opendir($path) )
{

Johno M
05-01-2005, 01:48 PM
now i get

Parse error: syntax error, unexpected T_STRING in e:\domains\angelsofdeath.dmwbattleservers.com\wwwroot\practise\index.php on line 72

bradgrafelman
05-01-2005, 02:30 PM
Can you repost the code you're using? Especially the code around line 72.

Johno M
05-01-2005, 05:00 PM
Ok, this is the ORIGINAL code, before I added the part that was posted.

-------------------------------------------------


<?php

$display = 10;

if ( $handle = opendir("news/") )
{
while ( ( $file = readdir( $handle ) ) !== false )
{
if ( $file != "." && $file != ".." )
{
$news_array[] = $file;
}
}
closedir( $handle );
}

array_multisort( $news_array, SORT_NUMERIC, SORT_DESC );
array_splice( $news_array, $display );

$num_news = ( count( $news_array ) );

foreach ( $news_array as $val )
{
$news_file = file("news/$val");

$title = $news_file[1];
$date = $news_file[0];
$text = $news_file[2];

echo '<center><table width="98%"><tr><td align="left" class="news"><p align="left"><font size="3">'.$title.'</font><font size="2"><i>'.$date.'</i>';
echo '</font></td></tr>';
echo '<table width="98%"><tr><td align="left" class="news"><p><font size="2">'.$text.'</font></td></tr></table>';
echo '<br>';
echo '<p>Powered by <a href="http://timurkz.buildtolearn.net">KZ Server</a><br>';
}
?>

<!--And the button for admin page-->
<a href="admin.php" class="mirror"><font size="1">Admin</font></a>


--------------------------------------------------------

Then I added the other bit :

<?php

$display = 10;

$path = $_SERVER['DOCUMENT_ROOT'] . 'news/';
if(!is_dir($path)) die('Error: <b>'.$path.'</b> is an invalid directory.');

if ( $handle = opendir($path) )
{
while ( ( $file = readdir( $handle ) ) !== false )
{
if ( $file != "." && $file != ".." )
{
$news_array[] = $file;
}
}
closedir( $handle );
}

array_multisort( $news_array, SORT_NUMERIC, SORT_DESC );
array_splice( $news_array, $display );

$num_news = ( count( $news_array ) );

foreach ( $news_array as $val )
{
$news_file = file("news/$val");

$title = $news_file[1];
$date = $news_file[0];
$text = $news_file[2];

echo '<center><table width="98%"><tr><td align="left" class="news"><p align="left"><font size="3">'.$title.'</font><font size="2"><i>'.$date.'</i>';
echo '</font></td></tr>';
echo '<table width="98%"><tr><td align="left" class="news"><p><font size="2">'.$text.'</font></td></tr></table>';
echo '<br>';
echo '<p>Powered by <a href="http://timurkz.buildtolearn.net">KZ Server</a><br>';
}
?>

<!--And the button for admin page-->
<a href="admin.php" class="mirror"><font size="1">Admin</font></a>



And I get this error:


Warning: array_multisort() [function.array-multisort.php]: Argument #1 is expected to be an array or a sort flag in e:\domains\angelsofdeath.dmwbattleservers.com\wwwroot\practise\index.php on line 76

Warning: array_splice() [function.array-splice.php]: The first argument should be an array in e:\domains\angelsofdeath.dmwbattleservers.com\wwwroot\practise\index.php on line 77

Warning: Invalid argument supplied for foreach() in e:\domains\angelsofdeath.dmwbattleservers.com\wwwroot\practise\index.php on line 81
Admin


Its different this time because I just re-did it