Results from the most recent live auction are here .
23 members in the live chat room. Join Chat !
05-28-2006, 01:20 PM
· #1 NamePros Regular
Join Date: May 2006
Posts: 225
NP$: 298.90 (
Donate )
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
05-28-2006, 01:50 PM
· #2 Buy my domains.
Name: Dan
Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 (
Donate )
$fileo = opendir();
Is the line that is causing it to not work.
You need to have a folder name in the ()'s.
05-28-2006, 02:55 PM
· #3 NamePros Regular
Location: mysitememberships.com
Join Date: Jul 2005
Posts: 925
NP$: 4800.90 (
Donate )
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 .
05-28-2006, 03:43 PM
· #4 while ($awake){ code(); }
Name: Eric
Location: Kentucky
Join Date: Mar 2005
Posts: 4,268
NP$: 1152.00 (
Donate )
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" ;
}
}
}
}
?>
Last edited by SecondVersion : 05-28-2006 at 04:13 PM .
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off