VaultNetwork.netVault Network Boards
Author Topic: Ok board for PHP/SQL help? Looking to make first/previous/next/last buttons [Locked]
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
[Edit out - didn't work. (well, worked great except for the manage page, then it would replace it's own code to replace code.) See next reply]

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
Friggin' FINALLY.

Here's final (php part of the) pages:

---------editfile.php:

<?php
if (isset($_GET['id'])) {
$file = $_GET['id'];
$fp = fopen($file, 'r+';
$content = fread($fp, filesize($file));
fclose($fp);
$replace = '</textarea>';
$newcontent = str_replace("</textarea>", $replace, $content);
echo '<center>
<form action="manage.php" method="post">
<textarea cols="125" rows="50" name="newcontent">'.$newcontent.'</textarea><br>
<input type="hidden" name="filetoedit" value="'.$file.'"><br>
<input type="submit" value="edit">
</form></center>';
}
?>

---------manage.php:

<?php
if (isset($_POST['filetoedit'])) {
$filetoedit = $_POST['filetoedit'];
$newcontent = $_POST['newcontent'];
$newcontent2 = stripslashes($newcontent);

if ($filetoedit != "/var/www/manage/manage.php" {
$newcontent3 = str_replace("replace = '</textarea>'", "replace = '</textarea>'", $newcontent2);
$fp = fopen($filetoedit, 'w+';
fwrite($fp, $newcontent3);
fclose($fp);
}

else {
$fp = fopen($filetoedit, 'w+';
fwrite($fp, $newcontent2);
fclose($fp);
}
}
?>

<napoleon dynamite>essssss</napoleon dynamite>

...good god almighty. That took almost 8 hours to figure out.

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Raiztlin  2 stars
Title: Dick Tracy
Posts: 397
Registered: 2002-1-23 08:10:37
Aha, ofcource :> told you it was something easy :]


The folder problem: check to see if the file you recieve has a file ending you accept, else fallback to listing a dir.

The dots: just skip the two first results from the array when you print.

 

-----signature-----
I has a flavor!
CC always welcome.
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
Started the ($i=2) to skip the dots..

As for the folder suggestion... Well, I have files with no .ext and some files that are something.something.something you know, so.. gunna have to figure that out.

One thing I could work with - All folder filesizes seem to be 4096 so far...

(Right now i have it printing filesize too)

This is super fun. But, I head home now and get ready to go see my neighbors daughter play in her school band.

Fun stuff, thanks for keepin' me company! Next up, later tonight or tomorrow afternoon - formatting manage.php and maybe putting in copy/delete/newfolder functions!

Funny thing is I'll probably rarely ever use this stuff. heh. Good to get practice though on a site that is fun to do.

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Raiztlin  2 stars
Title: Dick Tracy
Posts: 397
Registered: 2002-1-23 08:10:37
okay, in that case, check to see if you get an error before printing, if you do fall back to listing the dir :]

 

-----signature-----
I has a flavor!
CC always welcome.
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
Word, I like that.
I have some other pretty cool ideas too.

Going to a seminar this morning though.. sigh.

Stoopid werk.

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
Hey.. I wonder, can php be used to run a script in your filesystem?

edit: obviously... man I'm about to have some fun!

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
So it turned out my solution for the textarea problem was not solved, the manage page was still buggy and ended up overwriting itself with wrong data.. in teh replace the replacements string.

Then it hit me.

use include('closingtextareatag.php'

Reduced code and solved easily.

Why didn't I think of that long ago?

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
Man I hope you have some ideas on this. I'm pulling my hair out. Been messing with this for hours.

I'm trying to get it to make a temporary backup of files as I edit them, so I can revert and the click of a button. So I'm taking it a step at a time.

My problem is.. fopen should be creating a file for me, and it works if i just use a regular filepath/name.. but if I try to name it off a variable that's passed to the page, it refuses to open it.

<?php

# get variables
if (isset($_POST['filetoedit'])) {
$filetoedit = $_POST['filetoedit'];
$newcontent = $_POST['newcontent'];
$newcontent2 = stripslashes($newcontent);
# get variables

#backup old
$backupfile = "/media/backup_drive/wwwbackups/temp$filetoedit";
echo $backupfile;
$fpb = fopen($backupfile, 'a+';
#fwrite($fpb, $newcontent2);
#fclose($fpb);
#backup old

#write new
#$fp = fopen($filetoedit, 'w+';
#fwrite($fp, $newcontent2);
#fclose($fp);
#writenew

}
?>

As you can see the writing new is commented out while I figure this out, and so is half the backup script. So what happens, it gets the variables, sets the $backupfile, echo's it correctly, then errors on the fopen, says /correct/path/to/filenamename.php is 'not a file or folder'.

Well I know that, you're supposed to be creating it!

I've tried every combo I can of different ways to get it to work. If I take out the variable and just put

fopen("some/path/file.log", 'w+';

it works. But I need it to go work off the variable.

Thoughts? Ideas?

Edit: I wonder if name is too long? I found something like :

[ENAMETOOLONG] The length of the filename exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.

..when describing scenarios that cause it to fail, but the page from 97 and I couldnt' find PATH_MAX in php.ini...

It ends up being something like /media/backup_drive/backups/wwwbackups/temp/123/456/another/path/hereisfile.php

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull
Phases_OgMaxim  1 star
Posts: 52
Registered: 2002-7-16 16:32:23
I see. Turns out while fopen() can indeed create files, it can't create directories!

I got my 'oh shit backup' done!

It's tight. any time I edit a file on my web based file manager it automajically creates a backup of the file. At the moment the file gets overwrote with the next edit, so I've always got one behind me, but I have plans!

What I'd like to do is put a revert button up that lets me one click revert to the backup, in case of those (and I had one the other day) true 'oh shit' moments.
I also plan to have it save 3 or 5 .. haven't decided.. backups of each file and just replace the newest each time, pushing each version back one.

I think I can do it....

..then be able to revert back several version if I wanted.

Also, today I got all my log files put into text boxes on a couple pages, that works out nicely! Although, I think when my management area is mostly done and I find myself bored I might get my ajax learn on and tail 'em

 

-----signature-----
Every forum should have a Phases.
Bringing SSP back to life at http://www.superstickphase.com !
Retired AC/AC2 - Phases Og'Maxim - Leafcull

VaultNetwork.net is an independently operated community forum and is not affiliated with, endorsed by, or technically based on IGN, GameSpy, FilePlanet, GameStats, or the former IGN/GameSpy Vault Network.
References to VaultNetwork.net mean this site/domain. VNBoards-style presentation is a visual homage only. By using this site, you agree to the forum rules.