another noob needs help :@ :banghead:

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

evan_lone
Forum Newbie
Posts: 11
Joined: Mon Oct 31, 2011 1:09 am

another noob needs help :@ :banghead:

Post by evan_lone »

m facin' some problem, i alwys get the same file even after editing the file.
This is the code that i use to download the edited file:

Code: Select all

<?php $ipaddress = getenv(REMOTE_ADDR); $filename = "$ipaddress.txt";
$filepath = "./".$filename; header("Cache-control: private"); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Length: ' . filesize($filepath)); header('Content-Disposition: attachment; filename=' . $filename); ob_clean();
flush();
readfile($filename);
exit(done);
?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: another noob needs help :@ :banghead:

Post by social_experiment »

What does the file edit script look like?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
evan_lone
Forum Newbie
Posts: 11
Joined: Mon Oct 31, 2011 1:09 am

Re: another noob needs help :@ :banghead:

Post by evan_lone »

here it is:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
  <title>webpad</title>
</head>
<body background="ntpdbg.png">
<body></body>
<?php $data = $_POST['webpad'];
$ipaddress = getenv(REMOTE_ADDR);
$myFile = "$ipaddress.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "$data\n";
fwrite($fh, $stringData); fclose($fh);
echo "congrates ! Your data is saved ";?>
<a href="./paddwnld.php">here</a></html>
i got the string from a form.
evan_lone
Forum Newbie
Posts: 11
Joined: Mon Oct 31, 2011 1:09 am

Re: another noob needs help :@ :banghead:

Post by evan_lone »

here is the form:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
  <title>WebPad</title>
</head>
<body background="ntpdbg.png">
<img src="./trans.png" alt="i" />
<body>
<p>
<h4>Type/Paste here !</h4>
</p>
<form action="webpad.php"
method="post"><textarea rows="5" cols="20" name="webpad" wrap="physical">Enter your favorite quote!</textarea><br/>
<input type="submit" name="save" value="Submit N Download"/>
<h4><a href="./abt/webpadabt.html">about</a><h4></body>
</html>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: another noob needs help :@ :banghead:

Post by social_experiment »

Try using the 'a' flag with fopen instead of the 'w' flag. The 'a' flag will move the file pointer to the end of the file so you can add (or append) to the file.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
evan_lone
Forum Newbie
Posts: 11
Joined: Mon Oct 31, 2011 1:09 am

Re: another noob needs help :@ :banghead:

Post by evan_lone »

@social_experiment: actualy what i want is the file to be rewritten! Though i already tried the 'a' flag :)
but i 've to wait for ages to download the newly edited file(it always gives me the last downloaded(before editing) file)
if you could spare me a minute here is the link http://loneapps.net16.net/loneapps/webpad/webpad.html
(please use a phone's browser as it is designed for small displays)
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: another noob needs help :@ :banghead:

Post by social_experiment »

evan_lone wrote:but i 've to wait for ages to download the newly edited file(it always gives me the last downloaded(before editing) file)
I tested it and it opened pretty quickly after i entered a quote, and it displayed the last value i entered
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
evan_lone
Forum Newbie
Posts: 11
Joined: Mon Oct 31, 2011 1:09 am

Re: another noob needs help :@ :banghead:

Post by evan_lone »

social_experiment wrote:
evan_lone wrote:but i 've to wait for ages to download the newly edited file(it always gives me the last downloaded(before editing) file)
I tested it and it opened pretty quickly after i entered a quote, and it displayed the last value i entered
i m a bad speaker, pardon me for writing too long, say i entered the qoute 'hello' first time i enter the site and download it the downloaded files contents will be 'hello' but if i again enter another value say 'bye' and download it the file's contents won't be 'bye' instead it would come as 'hello' which is the value i just entered before.
I've tried many things but every time i end up with the same problem or an err msg.
Of course you will get the new file but like i said only after waiting for the 'server to refresh' try it.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: another noob needs help :@ :banghead:

Post by social_experiment »

evan_lone wrote:say i entered the qoute 'hello' first time i enter the site and download it the downloaded files contents will be 'hello' but if i again enter another value say 'bye' and download it the file's contents won't be 'bye' instead it would come as 'hello' which is the value i just entered before.
I entered submitted the form with default content and when i viewed the text file i saw the correct text, then i used my browser button to go back and entered a new value, which when submitted and viewed is displayed correctly. I couldn't recreate the problem you describe.
evan_lone wrote:I've tried many things but every time i end up with the same problem or an err msg.Of course you will get the new file but like i said only after waiting for the 'server to refresh' try it.
Can you paste the error message if you receive it. If i receive the new message i entered i would assume the script is working. I don't quite understand what you mean by 'server to refresh' but i would say that's normal because the script is writing to a file which might take time.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
evan_lone
Forum Newbie
Posts: 11
Joined: Mon Oct 31, 2011 1:09 am

Re: another noob needs help :@ :banghead:

Post by evan_lone »

or is it my device that is wrong!?
But what i guess(as a newbie) is that it is the server that is slow.
But thanks so much for givin' your precius time out here!
Regards.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: another noob needs help :@ :banghead:

Post by social_experiment »

evan_lone wrote:or is it my device that is wrong!?But what i guess(as a newbie) is that it is the server that is slow.
It's possible that the connection is slow, what type of connection do you use through the device?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
evan_lone
Forum Newbie
Posts: 11
Joined: Mon Oct 31, 2011 1:09 am

Re: another noob needs help :@ :banghead:

Post by evan_lone »

social_experiment wrote:
evan_lone wrote:or is it my device that is wrong!?But what i guess(as a newbie) is that it is the server that is slow.
It's possible that the connection is slow, what type of connection do you use through the device?
oh, we dont have fast connection here in manipur, :P but i used edge connection, its pretty fast. And of course the 'congrates ! Your file is saved here'(hope you get me) page loads really fast so as the download. Did you got the file downloaded or displayed on the browser's window ? Once i managed the file to be displayed but at that time there was no problems, the browser always instantly displayed corectly every time i summit.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: another noob needs help :@ :banghead:

Post by social_experiment »

evan_lone wrote:Did you got the file downloaded or displayed on the browser's window ?
The browser gives an option that let's you either open it or save it, i opened it and saw it's contents.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
evan_lone
Forum Newbie
Posts: 11
Joined: Mon Oct 31, 2011 1:09 am

Re: another noob needs help :@ :banghead:

Post by evan_lone »

social_experiment wrote:
evan_lone wrote:Did you got the file downloaded or displayed on the browser's window ?
The browser gives an option that let's you either open it or save it, i opened it and saw it's contents.
:!: please use a mobile browser(preferably opera mini or default for it was designed) to see the problem, please!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: another noob needs help :@ :banghead:

Post by social_experiment »

Tested it on the default browser on my mobile, got the quote i entered, my mobile however uses a fast connection as well.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply