www.webdeveloper.com
Results 1 to 12 of 12

Thread: Need (simple?) html directory for public - help plz

  1. #1
    Join Date
    Apr 2014
    Posts
    9

    Question Need (simple?) html directory for public - help plz

    Hi,
    I've been html coding and administrating my own Company website now for 8 years, but I don't know how to do what I want to do now. No, I've never used FrontPage or any other website builder software, I just hard-code the html myself. Learned how in College 10yrs ago. So all my web pages are just hard-coded html without even css. Well I just want to do a simple thing now, and I can't figure out how to do it. I have "Linux" web hosting.

    I want to put dozens of files in a directory, and let the public have access to them (they are screenshot pictures). Actually I already have them there, I just don't know how to let the public have access to them. When I try to access the directory with my web browser, it says "Permission denied" (Apache). And since I just want the public to be able to access them on their web browser, I don't want to use passwords to access it. I could hard-code an index page, but then I would have to manually add every filename to the list on that page in order to keep up with the directory contents. How can I do this automatically, without hard-coding every directory contents change?

  2. #2
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    the easiest methods would be add an .htaccess file to the directory and add replace {path} with the actual path to the directory (i.e. /root/path/to/dir/). i can't remember if relative paths can be used:
    Code:
    <Directory "{path}">
        Options Indexes
    </Directory>
    another method would to use a server-side script to list the directory contents. example in php:
    PHP Code:
    <html>
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title></title>
    </head>
    <body>
    <?php
    $files 
    glob('./*.{gif,jpg,png}'GLOB_BRACE);

    if(
    $files)
    {
        foreach(
    $files as $fn)
        {
            echo 
    '<a href="' .$fn'">' .$fn'</a><br>';
        }
    }
    ?>
    </body>
    </html>

  3. #3
    Join Date
    Apr 2014
    Posts
    9
    Quote Originally Posted by ShrineDesigns View Post
    the easiest methods would be add an .htaccess file to the directory and add replace {path} with the actual path to the directory (i.e. /root/path/to/dir/). i can't remember if relative paths can be used:
    Code:
    <Directory "{path}">
        Options Indexes
    </Directory>
    another method would to use a server-side script to list the directory contents. example in php:
    PHP Code:
    <html>
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title></title>
    </head>
    <body>
    <?php
    $files 
    glob('./*.{gif,jpg,png}'GLOB_BRACE);

    if(
    $files)
    {
        foreach(
    $files as $fn)
        {
            echo 
    '<a href="' .$fn'">' .$fn'</a><br>';
        }
    }
    ?>
    </body>
    </html>
    In the first case, what would I call that file? Index.htaccess? So this changes the permissions for the directory?

    In the second case, would that be Index.php? Would I have to make an HTML file that accesses it? Or is this the code that I would put in Index.html?

    This is PHP code? It looks a lot like C. I understand echo as a command, I used to code in Basic decades ago (and C and a little assembly).

  4. #4
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    .htaccess uses ".htaccess" as a filename. Options Indexes makes your server serve a "default" index that is a generated list of the files in the directory.

    yes, index.php would act as the same as index.html or index.htm would.
    the php in my previous post grabs an array of all png, jpg, and gif files (in the current directory) and produces html links to them.

    php has a few functions that are native in C#. php had more in common with perl than C#.

  5. #5
    Join Date
    Apr 2014
    Posts
    9
    As far as the .htaccess file is concerned, I had some trouble. So I did some Googling about it, and found some info. However, I still can't get it to work, when I do I get this error:

    Code:
    Internal Server Error
    
    The server encountered an internal error or misconfiguration and was unable to complete your request.
    
    Please contact the server administrator, myemail@provider.net and inform them of the time the error occurred, and anything you might have done that may have caused the error.
    
    More information about this error may be available in the server error log.
    Apache/2.2.3 (Red Hat) Server at www.mysite.com Port 80
    I tried the following contents:

    Code:
    <Directory "//html/Public/ESO">
        Options Indexes
    </Directory>
    I tried every possible combination with single and double fwd slashes, with/without the "html" (root) directory, and with "www" as I seen it in the "Apache HTTP server tutorial" about .htaccess files. I tried putting the "www/" in front of "/http/", and without. I still get this error as long as the file is in the directory.

    Now I will explore option 2.

  6. #6
    Join Date
    Apr 2014
    Posts
    9
    Oh yeah, I forgot to mention: My root has an .htaccess file as follows:

    Code:
    # THE TWO LINES BELOW WERE ADDED BY WEB.COM SO THAT YOUR SITE USES PHP4 INSTEAD OF PHP5
    AddHandler php4-script .php
    Action php4-script /system-cgi/php4
    And I never put a double slash in a directory string unless it is at the beginning.

  7. #7
    Join Date
    Apr 2014
    Posts
    9
    So I know that .htaccess files are allowed...

  8. #8
    Join Date
    Apr 2014
    Posts
    9
    Oh I just found another .htaccess file in the "/" directory above the "html" directory:

    Code:
    
    ErrorDocument 404 /error/mt404.html
    That's all it has in it. FYI.

  9. #9
    Join Date
    Apr 2014
    Posts
    9
    I checked the log file regarding the .htaccess file and found this repeatedly:

    Code:
    /home/cluster1/data/c/t/1226238/html/Public/ESO/.htaccess: <Directory not allowed here
    Apr 15 10:19:55 10.2.150.73: 34639:[error] [client 75.104.148.179] /home/cluster1/data/c/t/1226238/html/Public/ESO/.htaccess: <Directory not allowed here
    Apr 15 10:37:52 10.2.150.83: 34639:[error] [client 75.104.148.179] Directory index forbidden by Options directive: /home/cluster1/data/c/t/1226238/html/Public/ESO/

  10. #10
    Join Date
    Apr 2014
    Posts
    9
    Solved!
    Thnx ShrineDesigns.
    The second method recommended worked.

  11. #11
    Join Date
    Apr 2014
    Posts
    9
    This may be pushing what I could ask of you, but with the php method above, is there a way to show thumbnails? I could upload the resized images.

  12. #12
    Join Date
    Oct 2013
    Posts
    556
    See this:
    http://sye.dk/sfpg/

    Drop-dead simple to use.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles