Solved

AJAX,FOPEN, Inline Edit?

Posted on 2008-10-24
5
786 Views
Last Modified: 2009-11-01
Is this possible?
I would like to be able to do a inline edit on some text via AJAX and actually update the file I'm working on via PHP's FOPEN.

Some sample or pseudo code would be nice.

Thanks,
Scott

If not possible, points will be awarded to those who provide explanation and/or documentation why.
0
Comment
Question by:thcit
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:nick_bal
ID: 22800212
Can you please be more specific? It sounds like you know the basic principles of ajax and just want to use fopen inside ajax. Is this correct?
0
 
LVL 3

Author Comment

by:thcit
ID: 22814281
I guess what I'm asking in the grand scheme of things is: is it possible to edit the static contents of an html page that is currently being viewed by the user?  Here's what I have in mind.

User lands on page.html
Then clicks on the text in which an inline edit concept is used to make that text submittable.
After editing text, submit the information via AJAX to another PHP page that utilizes some regex and FOPEN to find the text and replace it with the data submitted.
The page then is reloaded asynchronously and changes are reflected.

Is that any clearer?
0
 
LVL 1

Accepted Solution

by:
nick_bal earned 500 total points
ID: 22823851
Ok below you can find what you asked but it's not with ajax and doesn't reload the page.
I will do that and post it here.. It's just that i didn't have the time to do that.. Hope it helps for now..
<?
if($_REQUEST['action']=="open"){
	$filetoopen = $_POST['file'];
	$fp=fopen($filetoopen, "r");
	$t="";
	while(!feof($fp)) {
	  $t.=fread($fp,1024);
	}
	fclose($fp);
}
 
if($_REQUEST['action']=="edit"){
	$filetoedit = $_POST['file'];
	$script = $_POST['script'];
	$fp=fopen($filetoedit, "w");
	fwrite($fp,$script);
	fclose($fp);
}
?>
 
<form action="index.php?action=open" method="post">
File: <input type="file" name="file"><br>
<input type="submit" value="Open File">
</form>
<br>
<? if($_REQUEST['action']!=""){?>
<form action="index.php?action=edit" method="post">
Code:<br>
<textarea cols="100" rows="20" name="script"><? if($_REQUEST['action']=="open"){echo $t;}else{echo $_POST['script'];}?></textarea>
<input type="hidden" name="file" value="<? echo $_POST['file']?>">
<br>
<input type="submit" value="Edit File">
</form>
<? }?>

Open in new window

0
 
LVL 3

Author Comment

by:thcit
ID: 23034729
Nick,
Have you had time to do the ajax side of your solution?  I haven't had time to test the code above just yet. Priorities just got rearranged.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now