Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Php problem

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

hell-knight

Established Member
Impact
0
Please tell me whta i did wrong in this attached php file (renamed to txt, so it wold be valid as attachement.


It displays in browser:

Warning: Wrong parameter count for opendir() in c:\usr\apache\httpd\html\notepad\open.php on line 103

Warning: readdir(): supplied argument is not a valid Directory resource in c:\usr\apache\httpd\html\notepad\open.php on line 104

and some php code around the document. Pls help
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
$fileo = opendir();

Is the line that is causing it to not work.

You need to have a folder name in the ()'s.
 
0
Close
well first off, i found acouple of things wrong.

you did not have a <? tag at the beginning after the include. also, im not sure that there shud be a space between include and ('head.inc'). finally, y do u have '.' inside each opendir? is that the file path?

<?php include('header.inc'); ?>

<?
$fh = opendir('.');
while($file = readdir($fh)){
if(!is_dir($file)){
if($file !== "script.php" && filesize($file) > "0"){
echo "<a href=\"". $HTTP_SERVER_VARS['PHP_SELF'] ."?file=$file\">". $file ."</a> . ";
echo " <small><a href=\"$file\">View the File</a></small><br />\n";
}
}
}

if(isset($_GET['file'])){
}
else{
$fh = opendir('.');
while($file = readdir($fh)){
if(!is_dir($file)){
if($file !== "script.php" && filesize($file) > "0"){
echo "<a href=\"". $HTTP_SERVER_VARS['PHP_SELF'] ."?file=$file\">". $file ."</a> . ";
echo " <small><a href=\"$file\">View the File</a></small><br />\n";
}
}
}
}
$file = $_GET['file'];
echo "Editing File: ". $file;
$handle = fopen($file, "r+");
$page_contents = fread($handle, filesize($file));
?>

<form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
<input type="hidden" value="<? echo $file; ?>" name="file" />
<textarea name="page_contents_updated" cols="100" rows="10"><? echo $page_contents; ?></textarea><br />
<input type="submit" value="Submit" name="submit" />
</form>
<a href="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>">Go back</a> to the file listing.
<?

if(isset($_GET['file'])){
$file = $_GET['file'];
echo "Editing File: ". $file;
$handle = fopen($file, "r+");
$page_contents = fread($handle, filesize($file));
?>

<form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
<input type="hidden" value="<? echo $file; ?>" name="file" />
<textarea name="page_contents_updated" cols="100" rows="10"><? echo $page_contents; ?></textarea><br />
<input type="submit" value="Submit" name="submit" />
</form>
<a href="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>">Go back</a> to the file listing.
<?
}
elseif($_POST['submit']){
}
else{
$fh = opendir('.');
while($file = readdir($fh)){
if(!is_dir($file)){
if($file !== "script.php" && filesize($file) > "0"){
echo "<a href=\"". $HTTP_SERVER_VARS['PHP_SELF'] ."?file=$file\">". $file ."</a> . ";
echo " <small><a href=\"$file\">View the File</a></small><br />\n";
}
}
}
}
?>

$pcu = $_POST['page_contents_updated'];
$h = fopen($file, "w");
fwrite($h, $pcu);
echo "The information was updated.<br />\n";
echo "<a href=\"". $HTTP_SERVER_VARS['PHP_SELF'] ."\">Go back</a> to the file listing.";
fclose($h);

<?
if(isset($_GET['file'])){
$file = $_GET['file'];
echo "Editing File: ". $file;
$handle = fopen($file, "r+");
$page_contents = fread($handle, filesize($file));
?>

<form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
<input type="hidden" value="<? echo $file; ?>" name="file" />
<textarea name="page_contents_updated" cols="100" rows="10"><? echo $page_contents; ?></textarea><br />
<input type="submit" value="Submit" name="submit" />
</form>
<a href="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>">Go back</a> to the file listing.
<?
}
elseif($_POST['submit']){
$pcu = $_POST['page_contents_updated'];
$h = fopen($file, "w");
fwrite($h, $pcu);
echo "The information was updated.<br />\n";
echo "<a href=\"". $HTTP_SERVER_VARS['PHP_SELF'] ."\">Go back</a> to the file listing.";
fclose($h);
}
else{
$fileo = opendir();
while($file = readdir($fileo)){
if(!is_dir($file)){
if($file !== "script.php" && filesize($file) > "0"){
echo "<a href=\"". $HTTP_SERVER_VARS['PHP_SELF'] ."?file=$file\">". $file ."</a> . ";
echo " <small><a href=\"$file\">View the File</a></small><br />\n";
}
}
}
}
?>
 
Last edited:
0
Close
Noticed a few things wrong, for one.. looping over the directory wrong ;) Will post an edited version in a minute.

Ok, here.. and I've tested it, seems to work just fine. You had alot of unnecessary code, etc.

EDIT: if you're going to be editing php files etc, then you should use:

PHP:
<?php

include('header.inc');

if (isset($_GET['file']))
{
    $file = trim(strip_tags($_GET['file']));

    echo 'Editing File: ' . $file;

    $handle = fopen($file, "r+");
    
    if (!$handle)
    {
        die('Error opening file: ' . $file);
    }
    
    $page_contents = fread($handle, filesize($file));

    echo '<form action="' .  $_SERVER['PHP_SELF'] . '" method="post">
    <input type="hidden" value="' . $file . '" name="file" />
    <textarea name="page_contents_updated" cols="100" rows="10">' . htmlentities($page_contents) . '</textarea><br />
    <input type="submit" value="Submit" name="submit" />
    </form>
    <a href="' . $_SERVER['PHP_SELF'] . '">Go back</a> to the file listing.';
}
else if(isset($_POST['submit']) AND $_POST['submit'] != '')
{
    if (PHP_VERSION < '4.3.0')
    {
        function html_entity_decode($string)
        {
            // replace numeric entities
            $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
            $string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);
            // replace literal entities
            $trans_tbl = get_html_translation_table(HTML_ENTITIES);
            $trans_tbl = array_flip($trans_tbl);

            return strtr($string, $trans_tbl);
        }
    }
    
    $pcu = trim(html_entity_decode($_POST['page_contents_updated']));
    $file = trim($_POST['file']);
    
    $fh = fopen($file, "w");
    
    if (!$fh)
    {
        die('Error opening file: ' . $file);
    }
    
    fwrite($fh, $pcu);

    echo 'The information was updated.<br />' . "\n";
    echo '<a href="' . $_SERVER['PHP_SELF'] . '">Go back</a> to the file listing.';
    
    fclose($fh);
}
else
{
    $fh = opendir('.');

    while (false !== ($file = readdir($fh)))
    {
        if (!is_dir($file))
        {
            if ($file != 'script.php' AND filesize($file) > 0)
            {
                echo '<a href="' . $_SERVER['PHP_SELF'] . '?file=' . $file . '">' . $file . '</a>';
                echo ' <small><a href="' . $file . '">View the File</a></small><br />' . "\n";
            }
        }
    }
}

?>
 
Last edited:
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back