 |
 |
editing a file with php?
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
I am setting up a quick system for this band's web site so that they can post news to the site easily. The posting works fine, but I want to make the posts editable. What I did was make each post save as a text file with the title of the file being a numeric date and time (12 digits) ending with the .post extension. What I am trying to create now is the admin page so that the band can click a link that says "edit post" and it will bring up a page with the contents in a text field. once the contents is there I know how to make it save changes.
So basically what I need is a php script that can take an argument of some kind. Is this what REQUEST is? I don't really know how to use that. (Sorry I'm new to PHP and web programming). What I was thinking is that I could make those "edit post" links link to a URL of a php file but append ?filename.post to the end so that the php script knows what file to open.
So my real question is, how in the PHP script do I access the text that's after the question mark (the filename that I want to edit)? And also, how do I make the file appear in the text box (I think I can figure this one out though).
Thanks.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Aug 2002
Location: 127.0.0.1
Status:
Offline
|
|
Why did you use textfiles and not a mysql database? I find mysql to be more secure, faster, and smaller. If you didnt use mysql at all what did you do the passwords in?
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2001
Location: somewhere
Status:
Offline
|
|
The portion after the '?' is called the Query String, and is populated into $_GET[]. The format is ParameterName=Value:
index.php?Filename=4587296587269.post
$_GET["Filename"] would return '4587296587269.post'
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
Originally posted by Colonel_Panic:
Why did you use textfiles and not a mysql database? I find mysql to be more secure, faster, and smaller. If you didnt use mysql at all what did you do the passwords in?
I am planning on password authenticating with apache. I have very little experience with mySQL (basically just creating databases to be used with phorum and phpBB) so I'm not really sure I want to use it. I guess this could be a good learning experience but I want to get it running soon. If you want to explain to me how to do it quickly I would really appreciate it.
Originally posted by wallinbl:
The portion after the '?' is called the Query String, and is populated into $_GET[]. The format is ParameterName=Value: index.php?Filename=4587296587269.post
$_GET["Filename"] would return '4587296587269.post'
Thanks. I figured that out after a while.
My big question is how do I make the same php file load the file for editing and then when the user clicks "save" it saves the file? If I use the POST method do I need 2 php files? If I make the form post to itself it doesn't work.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Dec 2002
Status:
Offline
|
|
Originally posted by waffffffle:
My big question is how do I make the same php file load the file for editing and then when the user clicks "save" it saves the file? If I use the POST method do I need 2 php files? If I make the form post to itself it doesn't work.
The POST method is just another way to pass information to the next page, like GET, except that POST stores the information in the header (I believe) of the page request. This is not what you want to do. Using the GET method as previously discussed will work just fine.
On the page that they edit the file you will want some type of "Save Changes" button that will cause the old file to be overwritten with the new data they entered. Look into fwrite(). Although that might not be the exact (or only) function you'll need, it should get you started. Check out the whole FILESYSTEM section that loads on the left side when you follow the link.
Also, you may want to consider some type of backup system before overwriting with the new data. Just think if an admin accidentally clears the edit field and presses enter, all is lost! Good luck.
|
|
Travis Sanderson
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
OK, I think I have it all working. However I would like to do a javascript confirmation to delete files. Right now I have a "DELETE POST" link that links to delete.php?FILENAME.post. How can I have a javascript confirmation for this? Should I do it on the same page that the link is or should I put it withing the delete.php page?
Thanks for all the help everyone. You can see my work in progress at http://semaya.no-up.org/lastweek2
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2001
Location: somewhere
Status:
Offline
|
|
Originally posted by waffffffle:
OK, I think I have it all working. However I would like to do a javascript confirmation to delete files. Right now I have a "DELETE POST" link that links to delete.php?FILENAME.post. How can I have a javascript confirmation for this? Should I do it on the same page that the link is or should I put it withing the delete.php page?
Thanks for all the help everyone. You can see my work in progress at http://semaya.no-up.org/lastweek2
Do it in the page that has the link. You want to create a javascript function that basically looks like this:
Code:
function ConfirmDelete()
{
if (confirm('Are you sure you want to delete this file?'))
{
document.location.href='http://www.yoursite.com/deletefile.php';
}
}
Then, on your button (or hyperlink):
<INPUT TYPE=Button ID=DeleteButton VALUE='Delete File'
onClick='javascript : ConfirmClearCurrentOrder();'>
If you are going to repeat this for many files, you can alter the function to accept either the filename or the URL (including filename) as a parameter and then do document.location.href=pURL or something like that.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
Originally posted by wallinbl:
If you are going to repeat this for many files, you can alter the function to accept either the filename or the URL (including filename) as a parameter and then do document.location.href=pURL or something like that.
That is exactly my question. How do I make the function take in variables?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
actually i think i got it, thanks
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum 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
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|