Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts

    Getting and defining functions from hyperlink

    Hey guys. I need some help here

    I'm trying to build a text editor. But i don't know how to define function from hyperlink. I know how to use $_GET and that, but this is what i need.

    Folders are like this

    --includes
    --files
    -index.php

    My index.php contains function that reads Files dir, and includes some functions to use in editor, that's write.php. Editor is also in includes folder, that is editor.php.

    Now in index.php i generated my links with simple readdir found on php.net like this

    PHP Code:
    if ($handle opendir('files')) {
        while (
    false !== ($file readdir($handle))) {
            if (
    $file != "." && $file != "..") {
    #this is the problem part
                
    echo "<a href=\"?edit=$file\">$file</a><br />";
            }
        }
        
    closedir($handle);

    Now i think that ?edit=$file can be used to call edit function which is defined in some other file like write.php

    But i have this problem with editor.php, where i want to use my textarea to edit that file. It looks like this

    PHP Code:
    <form method="POST">
    <p><input id="title" name="title"></p>
    <p><textarea name="tekst" wrap="virtual">
    <?php #what to write here so that it uses that ?edit=$file link ?>
    </textarea></p>
    <p><input type="submit"></p>
    </form>
    I guess this could be solved with using sessions, but i don't think that that is necessary, and i would really like for u guys to help me figure this out.

    Thanks

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The query string of the URL will be stored in the $_GET array for your use. So if you were to just add ?doyouliketacos=hellyes to any URL, PHP would provide that script a $_GET['doyouliketacos'] variable with value 'hellyes'.

  • #3
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Let's see if I have this right:
    1) You have index.php that lists your files in the files directory (folder)
    2) write.php is in the files directory
    3) When you click on the link yourdomain.com/index.php?edit=write.php (which is listed in #1), it should open editor.php and include the write.php file in editor.php's textarea.

    If all that is correct, then you'll have this in editor.php:
    PHP Code:
    <form method="POST"> 
    <p><input id="title" name="title"></p> 
    <p><textarea name="tekst" wrap="virtual"> 
    <?php include_once "files/" $_GET['edit']; ?> 
    </textarea></p> 
    <p><input type="submit"></p> 
    </form>
    HTH!

    -Shane

  • #4
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    @TheShaner

    actualy my domain then looks yourdomain.com/index.php?edit=My%20Title.txt

    and now i see the missing link, you see that is not just an editor but also a viewer of those text files, and i forgot the part where i have links to NEW, EDIT, DELETE, and SAVE functions. Sorry about that, couse i'm still thinking about the whole concept.

    Basicly first part is the links part where i have PHP generated links to text files like this

    <a href="index.php?show=My Title.txt">My Title</a>
    <a href="index.php?show=My Title2.txt">My Title2</a>

    In the middle content can be displayed with simple use of get. That is the part i forgot to mention.

    Ok, now on the right corner i have Admin tools like NEW, EDIT, which are basicly

    <a href="new.php">NEW</a>
    <a href="edit.php?edit=My Title2.txt">EDIT</a>

    So this is the tricky part, which i can't figure out.

    I don't want my admin tools to be like that, but i want them to be generated from included script in includes folder. So that instead my EDIT calls another file and edits that My Title2.txt like shown above, i want it to be shown in the middle section of the index.php.

    I only need guidance couse paths are bothering me since i've started this little script.. So let's say that in write.php i have functions like

    PHP Code:
    function new($file){
    #some php stuff to create new file and store it in [B]files[B] folder

    and

    PHP Code:
    function edit($file){
    #some php stuff that edits the egzisting file

    How can i call those functions just by including write.php in index.php.

    This sounds really complicated, and maybe i'm just missing the obvious couse i haven't slept well these days.

    Thanks

  • #5
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    In edit.php, you'll have:
    PHP Code:
    include_once "files/write.php";
    if (isset(
    $_GET['edit'])) edit($_GET['edit']); 
    The above will call your edit function in write.php and pass the file that edit was set to.

    -Shane

  • #6
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by TheShaner View Post
    In edit.php, you'll have:
    PHP Code:
    include_once "files/write.php";
    if (isset(
    $_GET['edit'])) edit($_GET['edit']); 
    The above will call your edit function in write.php and pass the file that edit was set to.

    -Shane
    Thank you


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •