/    Sign up×
Community /Pin to ProfileBookmark

Won’t write out entire source!

Hi. I’m currently working on a site manager script so I can update my website when I’m not at home. What I have so far is located [url=http://216.36.173.149/site.php]here[/url]. Login to the Site Manager section with the username “user” and the password “pass”. On the next page, click the “Open” button, and type “blog04.php” into the prompt window and click ok. Verify that the correct name is in the textbox, and then click “Open It!”. It should take you to a page with an IFRAME containing blog04.php, and then a textarea containing the source of blog04.php. Scroll down so you can see the textarea. The first line reads:

[code]<title>Daniel Tomasiewicz’s Personal Website | Who’s payin’ these guys?!</title>[/code]

However, the first line, when I open it in DW, is the following, just like it should be:

[code]<?php include(‘includes/preheader.xml’); ?>[/code]

I am using fopen() to open the file, and fread() to read it. It can’t be a problem with it parsing the PHP before it outputs it, because if you scroll down to the bottom of the source, you’ll see the PHP appears fine there. Any suggestions?? I’m stuck! Thanx,
-Dan

to post a comment
PHP

21 Comments(s)

Copy linkTweet thisAlerts:
@NevermoreApr 20.2004 — If you view your source you'll see this line:
[code=php]
<textarea style='margin:20px; width: 90%; height: 300px;><?php include('includes/preheader.xml'); ?>
[/code]


You missed the closing ' from the textarea style attribute, so the php code is being taken to be part of the tag.
Copy linkTweet thisAlerts:
@Daniel_TauthorApr 20.2004 — I should've noticed that!! Thanx man!

-Dan
Copy linkTweet thisAlerts:
@ConorApr 20.2004 — hmm i tride this but the code wont come up in the textarea what did i do wrong?
[code=php]
<form action="<?$_SERVER['PHP_SELF'];?>" method="POST">
<input type="text" name="file" value="Enter filename to edit"><input type="submit">
<?
$file=$_POST['file'];
if($file != "")
{
$fopen= fopen($file,'w+');
$fread= fread($fopen, $file);
echo"<textarea>".$fread."</textarea>";
}
?>
[/code]
Copy linkTweet thisAlerts:
@JonaApr 21.2004 — [i]Originally posted by RefreshF5 [/i]

[B][code=php]
<form action="<?$_SERVER['PHP_SELF'];?>" method="POST">
[/code]
[/B][/QUOTE]


[font=arial]Try using[/font]

[code=php]
<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST">
[/code]
Copy linkTweet thisAlerts:
@ConorApr 21.2004 — no heres the error im getting

Warning: fread(): Length parameter must be greater than 0. in C:Program FilesApache GroupApache2htdocsmanage-remote.php on line 8

[code=php]
<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST">
<input type="text" name="file" value="Enter filename to edit"><input type="submit">
<?
$file=$_POST['file'];
if($file != "")
{
$fopen= fopen($file,'w+');
$fread= fread($fopen, $file);
echo"<textarea>".$fread."</textarea>";
}
?>
[/code]
Copy linkTweet thisAlerts:
@JonaApr 21.2004 — [code=php]
<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST">
<input type="text" name="file" value="Enter filename to edit"><input type="submit">
<?
$file=$_POST['file'];
if($file != "")
{
$fopen= fopen($file,'w+');
$fread= fread($fopen, filesize($file));
echo"<textarea>".$fread."</textarea>";
}
?>
[/code]
Copy linkTweet thisAlerts:
@ConorApr 21.2004 — hmm, nope i get the same error.
Copy linkTweet thisAlerts:
@Daniel_TauthorApr 21.2004 — That error means that the file you are reading does not have any content.

-Dan
Copy linkTweet thisAlerts:
@JonaApr 21.2004 — [font=arial]You might want to close the file afterwards, and check to see if the variable isset before setting it to a new variable first to avoid errors, as well. ? [/font]

[code=php]
<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST">
<input type="text" name="file" value="Enter filename to edit"><input type="submit">
<?
if(isset($_POST["file"]))
{
$file = $_POST["file"];
if(filesize($file) > 0)
{
$fopen= fopen($file,'w+');
$fread= fread($fopen, filesize($file));
echo"<textarea>".$fread."</textarea>";
fclose($fopen);
}
}
?>
[/code]
Copy linkTweet thisAlerts:
@Daniel_TauthorApr 21.2004 — If it helps, here is the code I use:
[code=php]<?php
$thefile = $_POST['thefile2open'];
$openit = fopen($thefile, "r");
$existing = fread($openit, filesize($thefile));
fclose($openit);
print("<textarea>$existing</textarea>");

$open4write = fopen($thefile, "w+");
fputs("Whatever you want to write to the file.");
fclose($open4write);
?>[/code]

-Dan
Copy linkTweet thisAlerts:
@JonaApr 21.2004 — [font=arial]Daniel has a point, why not use the 'r' directive in your fopen() function, instead of the 'w+' one?[/font]
Copy linkTweet thisAlerts:
@ConorApr 21.2004 — because what about when i have to overwrite it, wont 'r' only read it?
Copy linkTweet thisAlerts:
@JonaApr 21.2004 — [i]Originally posted by RefreshF5 [/i]

[B]because what about when i have to overwrite it, wont 'r' only read it? [/B][/QUOTE]


[font=arial]Read it, close it, then when you need to overwrite it, open it, overwrite it, and close it again.[/font]
Copy linkTweet thisAlerts:
@ConorApr 21.2004 — hmm it was still throwing the same error so i tried another way of doing it and it does everything except actually overwrite the file?

[code=php]<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST">
<input type="text" name="file" value="Enter filename to edit"><input type="submit"><br>
<?php
$file=$_POST['file'];
$code= file_get_contents($file);

?>
<textarea rows=25 cols=75 name="edit"><?echo $code;?></textarea>
<input type="submit" name="overwrite" value="edit">
<?
$edit=$_POST['edit'];
if($edit != "")
{
$fopen= fopen($file , 'w+');
fwrite($fopen, $edit);
fclose($fopen);
$phrase="The File has been overwritten";
echo $phrase;
}
?>
[/code]
Copy linkTweet thisAlerts:
@Daniel_TauthorApr 21.2004 — I've edited my post above to make it so you can write to the file. Also, regarding the code you just posted, try changing it to this:
[code=php]<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST">
<input type="text" name="file" value="Enter filename to edit"><input type="submit"><br>
<?php
$file=$_POST['file'];
$code= file_get_contents($file);

?>
<textarea rows=25 cols=75 name="edit"><?echo $code;?></textarea>
<input type="submit" name="overwrite" value="edit">
<?
$edit=$_POST['edit'];
if($edit != "")
{
if(!($fopen = fopen($file , 'w')))
{
echo "File could not be loaded";
}
else
{
fwrite($fopen, $edit);
fclose($fopen);
$phrase="The File has been overwritten";
echo $phrase;
}
}
?> [/code]
Copy linkTweet thisAlerts:
@ConorApr 21.2004 — hmm that gave me a weird error ive never seen before

Parse error: parse error, unexpected T_ELSE in C:Program FilesApache GroupApache2htdocsmanage-remote.php on line 18
Copy linkTweet thisAlerts:
@Daniel_TauthorApr 21.2004 — OK, my bad. I put a semicolon after the fopen statement when I shouldn't have. I edited my post, and it should fix the error.

-Dan
Copy linkTweet thisAlerts:
@JonaApr 21.2004 — [font=arial]Why are you using "w+"? You should be using just the "w" without the plus sign. ?[/font]
Copy linkTweet thisAlerts:
@Daniel_TauthorApr 21.2004 — [i]Originally posted by Jona [/i]

[B][font=arial]Why are you using "w+"? You should be using just the "w" without the plus sign. ?[/font] [/B][/QUOTE]

I was wondering this too, but I didn't know if it affected the outcome or anything, so I just left it alone.

-Dan
Copy linkTweet thisAlerts:
@JonaApr 21.2004 — [font=arial]I was doing a counter script once, and I had used this; I instead read it with 'r,' and then wrote it with 'w,' and it worked fine; otherwise it appended exactly as if I had used 'a+.'[/font]
Copy linkTweet thisAlerts:
@NevermoreApr 21.2004 — That's because you had moved the file pointer to the end of the file by reading it first. If you use w+ to read then write it will append, if you close and reopen the file or use rewind() it will overwrite.
×

Success!

Help @Daniel_T spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...