SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Hybrid View

  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would i do this and what functions would i need. I am using PHP to do this.

    Basically, I want thte user to type in the address for this page, lets say: filemanage.php

    And it comes up with s ome options:

    1. Create Files
    2. Delete Files
    3. Upload Files
    4. Edit Files

    Also, how would i go about all the editing, deleting, creating.?

    For deleting, I would like the user to select a check box next to every file he wants to delete then it is deleted afterwards.

    I already know how to upload a file, however, I don't know how to display a list of directories and files and let the user choose which one he wants to upload to.

    Also, When creatiing a page would you use something like this:

    $text = "TEXT FROM FORM
    $name = "NAME from FORM
    $directory, displayed through a directory listing and using radio buttons.

    copy($text,'/home/petesmc/public_html/$directory', $name);


  2. #2
    SitePoint Addict
    Join Date
    Nov 2000
    Location
    London, UK
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is an example from the php.net php manual

    Example 1. List all files in the current directory

    Code:
    // Note that !== did not exist until 4.0.0-RC2
    <?php
    $handle=opendir('.');
    echo "Directory handle: $handle\n";
    echo "Files:\n";
    while (($file = readdir($handle))!==false) {
        echo "$file\n";
    }
    closedir($handle); 
    ?>
    Writing and reading to files:
    Check this page in the php manual:
    http://www.php.net/manual/en/ref.filesystem.php
    This is the filesystem reference you should find all the references you need to help you there.

    Good luck

    ... what's the world coming to?

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a way that I have ONE page, and the users can list files in a directory that they slected?

    Would i do this?

    $handle=opendir('$dir');

    Where dir comes from a previous lising?


    Also, this dir thing, does it only show directories or files or both?


  4. #4
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anyone write basic code on how to read a file, write a new file, edit a file, delete a file as i have gone through the manaul and i find that they give you like one function:

    eg.

    $fp = fopen ("http://www.codingclick.com", "r");


    But they don't say how to print it on the screen or edit, or delete it.

    Thanx to anyone that can help

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a native directory handling function called dir and no you would have to check to see if it is file or dir I usualyy put the files and the dirs into arrays

    $dirtoread = "/path/to/some/dir"; //Or passed from a query string

    $dir = dir($dirtoread);
    while($file = $dir->read()) {
    if (($file != ".") && ($file != "..") && is_file($file)) {
    $filelist[] = $file;
    }
    }
    $dir->rewind();
    while($file = $dir->read()) {
    if (($file != ".") && ($file != "..") && is_dir($file)) {
    $dirlist[] = $file;
    }
    }
    $dir->close();

    while(list($key,$val) = each ($dirlist)) {
    print "<b>".$val."</b><br>";
    }
    while(list($key,$val) = each ($filelist)) {
    print $val."<br>";
    }
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pete I doubt anyone is gonna write you the code out of the goodness of their own hearts; that is basically writing a whole application for you, you are better off figuring it out for yourself and asking specific questions here, not "How do I develop this huge application?" Good Luck! And ask about specific things.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well i found out how to delete a file:

    unlink("c:\phpweb/upload.php");

    But thats bascially all, I'm just asking for the real basics...

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well in my last post Ishowed you how to show the contents of a directory and how to separate files from dirs

    to create a file:

    $fp = fopen("filename", "w");
    fwrite($fp, $data);
    fclose($fp);
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx for that,

    How would i display the contents of a file? Would you use fread?


  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What kind of file? just link to it?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  11. #11
    exit();
    Join Date
    Jul 2000
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a lot of information on this topic at http://www.php.net/manual/html (Yes, I like the HTML version better.)

    I really don't see a need for this script either..? There are tons of nice ones out there in Perl and maybe some in PHP. Why use that when you can use FTP or those other scripts?

  12. #12
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A client of mine.....Yes, the person that nkows hardly anything to do with PHP, wants to be able to not have to use FTP for uploading files so he asked me if i could do this for him.

    We a trading skills, he is design a layout for my site, i am databasing his site.

    I know my job is allot harder, but he has also offered to display my banner on his site for a while.

    He gets 1Million hits a month so that should be good.

    How about editing thene, I want to read the file to output it to a teextarea then the edited version gets re-written, that why i need to read a file.

  13. #13
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [/B]A client of mine.....Yes, the person that nkows hardly anything to do with PHP, wants to be able to not have to use FTP[/B]
    You can use a hammer to drive a screw into wood - but the screwdriver has been specially designed to do that job much cleaner. The last time I checked FTP stood for File Transfer Protocol Content management interfaces are ok for ppl who don't have a clue; but if your friend is publishing a web site then in the long run isn't it just easier to teach him to use FTP. I mean, with GUI FTP clients such as CuteFTP (Win) or Fetch (Mac) it really is no bigger deal than using Exporer in Windows.

    Its a give a man a fish vs teaching him to fish thing

  14. #14
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah i know..i tried to explain this to him. But he doesn't want to use FTP.

    Even though he clearly knows how to use it.

    Its strange/..

    I might not do this file management thing for him as it is quite pointless...

    Thanx

  15. #15
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's a ready made script like this in PERL - have a look at FileMan on http://www.gossamer-threads.com

    it's a fantastic script and will save you a hell of a lot of time - writing a script like this in PHP could take weeks.

    If you do decide to write one yourself it is essential you beef up on security first - you'll need to check a lot of information from forms before letting the script use it in file system paths etc or you could end up with a trashed file system, lost data or worse.

  16. #16
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah except for perl stinks (Did I just say that out loud?) Pete it would be rather easy to write this in PHP, from your earlier posts it would seem that you have just about all the parts you would need except the reading a file in and putting it into a textarea for editing

    Basic Bare-bones code to display the contents of a file in a textarea then write the submitted data back to the file with no security checking or anything. So use it at your own risk but be cautioned that people could put potentially system crippling code in here that could damage your system when run.


    <?

    if ($submit) {
    $fp = fopen("dateclass.php", "w");
    fwrite($fp, stripslashes($newdata));
    fclose($fp);
    }








    $fp = fopen("dateclass.php", "r");
    while (!feof($fp)) {
    $data .= fgets($fp, 4096);
    }
    fclose($fp);






    ?>

    <html>
    <head>
    <title>Untitled</title>
    </head>

    <body>
    <form action="<? print $PHP_SELF; ?>" method="post">
    <textarea name="newdata" rows="60" cols="50">
    <?
    print $data;
    ?>
    </textarea>
    <br>
    <input type="submit" name="submit" value="Submit">
    </form>


    </body>
    </html>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  17. #17
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx allot for that code. I decided that I'm only going to make certain parts of this because of security wrisks you pointed out.

    I'm not allowing deleting of files or creation. But only editing. Even though this only minorly reduces security issues, it will be password protected and will be used for typos, etc.

    Thanx allot again for your help

  18. #18
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe I'm missing something obvious here.. but can you explain again why you insist on building this web application from scratch?

    Go to http://www.hotscripts.com/PHP/Script...le_Management/ and you will find programs such as this one:
    Personal Webspace is a set of PHP3 and PERL scripts that allows users to maintain their web pages using just their browsers. It allows users to upload file, create directories, and remove files/directories from the web sites. The idea behind Personal Webspace is to allow users to edit their own web pages without having to enable ftp services for them to upload their changed documents.
    or this one:
    PhpMyExplorer is a PHP application which allows you to easily update your site online without any FTP access. Like an explorer it allows you: to copy, move, delete, erase, or rename files and directories; to create directories; to upload files; to download files; to visualize the contents of the files; and customize the aspect of the application (language, colors, etc).
    There are 16 other listed programs that can do exactly what you want.

    So again I ask.. why do you want to reinvent the wheel for nothing? Seems like a real waste of time.
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  19. #19
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah but you are missing one minor detail. Anyone can use other people's programs but a real programmer can write their own. Sure I can sit here and install other people's scripts all day long, but I, and I have a feeling I speak for others around here, would like to know how to actually write these programs. So, in my case, I always write my own programs, I may download someone elses to see how they did something but then I incorporate their logic into my own program. That is what programming is all about.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  20. #20
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My personal opinion is that it's the results that matters. Period. Whether I choose to start a program from scratch, base it on someone elses (assuming no copywrite violations), or whatever.. if the result is what I need then it is good. As a paid programmer, I am obligated to get things finished as fast as possible. My employer is unwilling to pay me for 5 hours of work to "reinvent the wheel" when I can just buy a ready-made componenet for $50. When I work for myself, it make little sense to spend 5 hours trying to figure something out when I could simply copy it from somewhere in 10 minutes and then spend the 4.5 hours making more money on a different project.

    I do, however, understand your thought. It's a pride issue, I think. Sure, I might be able to churn out programs in 30 minutes by copying someone else.. but I can't do it myself.. on my own. I think there's a happy medium here for us here. petesmc, are you listening?

    I'm still learning PHP, too.. but rather than ask a dozen questions about basically the same thing.. and taking 5 hours to do a simple task, I will often just download 4 or 5 scripts that *already* do what I want. I study the scripts.. take them apart as best I can.. and then put them back together again into my own script. Most of your questions shouldn't be about "how do I do this", but should be "which method of doing this is better?"

    When petesmc asks "how do I" questions and we provide explicit step-by-step directions.. how is this different than asking him to "borrow" someone else's ready-made script and asking him to figure it out, as I suggest?

    grin.
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  21. #21
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy, I didn't mean to critisize.. because you have certainly helped me out in the past, too!! Your detailed code examples are awesome and always helpful.

    My point is that I don't think this is any different than getting a code example from a completed script.. if you can find it.

    If you can't find it.. then ask Freddy. 'Cause he will know how to do it! Man's a freaking genious he is..
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  22. #22
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I totally agree with you there, with regards to the nature of some of the questions posted here. But for me its more of a "I want to learn as much as I can" thing. So I often times find myself reinventing the wheel so I can make sure I have done the job up to my standards and learned exactly how and what the code does. That is probably why I hardly ever ask any questions here, because I want to figure out for myself how to do things. And I want to know how to do everything, I am sure I will never get to that point, because stuff changes everyday. But I know that if I write a program, I will know exactly how to fix it when it breaks, I know that I have struggled over trying to repair other people's scripts or if we install a pre-made script, and the boss says can you add this? Or can you take out this? I will know exactly how the program works and I won't be caught with my pants down
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  23. #23
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW, no offense taken!
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  24. #24
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx all on this...

    hstraf: I am doing this, because I want to be able to this for my own site oneday, and be able to customise this script the way that I want to. Freddy has got a very good point about Being able to fix/add things when needed. I couldn't do this with someone else program because of coding style.

    Even though I am relatively new, 1 month now, to PHP, I have found that I tend to do things different than many people here. Just the way I go about doing things..

    Freddy: Do you Code for a living? If not you should!

    And I got it working to the way I wanted with you guys' help!

    Thanx again, Pete


  25. #25
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I slave away at my job everyday writing PHP code. So much I feel as if I am gonna explode sometimes. Pete if I can give you some advice. You said

    Even though I am relatively new, 1 month now, to PHP, I have found that I tend to do things different than many people here. Just the way I go about doing things
    Try to keep an open mind, your method may work and not be like someone else's, but is it the most efficient way of doing something? Since you have only been at it for 1 month, I guarantee you that in six months you would look back on the code you are writing today and say "Why did I do that that way, when I could of, or I should have done it this way."

    What I am trying to say is that everyone's style has some good in it, unless you are a total bonehead! So try to pick up the good habits that you find in others' code and weed out the bad ones, then incorporate those concepts into your own code. But like I said in my previous post and in the past, write your own programs it will teach you lessons that you can't learn from using pre-made scripts for everything.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

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