[advanced search]
Results from the most recent live auction are here.
23 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Domain Name Industry Newsletter
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 05-28-2006, 01:20 PM   · #1
hell-knight
NamePros Regular
 
hell-knight's Avatar
 
Trader Rating: (6)
Join Date: May 2006
Posts: 225
NP$: 298.90 (Donate)
hell-knight is an unknown quantity at this point
Php problem

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


Please register or log-in into NamePros to hide ads
Attached Files
File Type: txt Open.txt (3.8 KB, 6 views)
hell-knight is offline   Reply With Quote
Old 05-28-2006, 01:50 PM   · #2
Dan
Buy my domains.
 
Dan's Avatar
 
Name: Dan
Trader Rating: (63)
Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 (Donate)
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
Autism Autism Autism Autism Autism Autism Autism
$fileo = opendir();

Is the line that is causing it to not work.

You need to have a folder name in the ()'s.
Dan is offline   Reply With Quote
Old 05-28-2006, 02:55 PM   · #3
nasaboy007
NamePros Regular
 
Location: mysitememberships.com
Trader Rating: (32)
Join Date: Jul 2005
Posts: 925
NP$: 4800.90 (Donate)
nasaboy007 is a splendid one to beholdnasaboy007 is a splendid one to beholdnasaboy007 is a splendid one to beholdnasaboy007 is a splendid one to beholdnasaboy007 is a splendid one to beholdnasaboy007 is a splendid one to beholdnasaboy007 is a splendid one to behold
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?

Quote:
<?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 by nasaboy007 : 05-28-2006 at 02:58 PM.
nasaboy007 is offline   Reply With Quote
Old 05-28-2006, 03:43 PM   · #4
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (142)
Join Date: Mar 2005
Posts: 4,268
NP$: 1152.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
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 Code:
<?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";
            }
        }
    }
}

?>
__________________

SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.3 now available!!

Last edited by SecondVersion : 05-28-2006 at 04:13 PM.
SecondVersion is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
Website Header Design Website Header Design Proof is in the Parking
Advertise your business at NamePros
All times are GMT -7. The time now is 11:42 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0