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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    New Coder
    Join Date
    Aug 2006
    Location
    Southeast Texas
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool creating links to image files automatically

    Good Morning All..

    Hopefully someone here can help me because I am at a loss as to what to do...

    I was told I need to do this with PHP but I have no idea how or where to begin.. I need some kind of explanation or tutorial "PHP for idiots"

    Here is what I would like to do... I create images and want to be able to post them on my website.. But I want to post the links to the images... Not the images themselves.... On one directory in my file manager.. I have just about 200 images... How would I go about adding a link to each of those images to my website without having to individually copy and paste the link...

    I would do image galleries or thumbnail views but they take a while to load.. so creating them as links would be better.... But I have no idea how to go about this.... Hopefully someone here can help... I've wasted 3 days trying to find out how to do this and got no where... I just hope I don't end up having to go about copying and pasting the links anyway lol... Because I have several directories to do this for

    Also please keep in mind I am a PHP idiot... so hopefully someone can explain it in idiot terms lololol

    Thanks!
    Jacki

  • #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
    You can use the glob() function to create an array of filenames from a directory and then echo html mark up from that array. Since you're new to PHP here is the syntax:

    PHP Code:
    <?php
    $images 
    glob("yourdir/*.jpg");
    foreach(
    $images as $fileName) {
        print 
    "<a href=\"yourdir/$filename\">$filename</a><br />\n";
    }
    ?>

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts

    More descriptive subject

    It's seems obvious you chose not to read our posting guidelines even though we've stated just about everywhere to do so before posting. In the future, please use a more descriptive subject when posting a question. See posting guidelines.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    New Coder
    Join Date
    Aug 2006
    Location
    Southeast Texas
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Link Directory Help

    My apologies Spookster!.. It's not that I chose not to read the posting guidelines... I only joined a couple of hours ago so I am still reading through things... And getting to know who things work here... Since I am also new to PHP I really have no idea of the "technical term" for what I need help with... I will keep my post subject more specific.... My apologies....

    Thank you Fumigator for the code.. Looks like a simple enough code.... Where do I put it?? LOL... Does it go inside with the HTML codes for the particular page where I want the images to go? Like I have a folder called "Angels" Would I place that code in the "index.htm" file I have in this directory?

    Thanks so much for the help! (and patience)

    Jacki

  • #5
    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
    You imbed php into any html file. Go through this tutorial here to get the hang of it.

  • #6
    New Coder
    Join Date
    Aug 2006
    Location
    Southeast Texas
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    Oh Lordy.. Out comes the idiot in me!!!

    I started out on a blank webpage... Added the code you posted.. And I KNOW there has got to be something I need to change in the code.. But not sure what because after I put the code inside the HTML file... All I get is this

    http://wickdimpressions.com/TestFolder/new_page_1.htm

    It's a blank page that says $filename and some symbols... no idea what they mean!! LOL.. Yeah I know I'm not bright... Lack common sense (sometimes)...

    What variables do I need to change within the code to get it to work?

    Thanks!!!
    Jacki

  • #7
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    yourdir needs to be the directory of your images for example "/images/*.jpg"
    or change the jpg to the extension of your images
    Last edited by rafiki; 08-30-2006 at 05:55 PM. Reason: mistake

  • #8
    New Coder
    Join Date
    Aug 2006
    Location
    Southeast Texas
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do you mean the full path? like wickdimpressions.com/images or just images/?

    I'm going to try again... Thanks rafiki!

    Jacki

  • #9
    New Coder
    Join Date
    Aug 2006
    Location
    Southeast Texas
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried.. I put in the location of the folder where the images are stored as wickdimpressions.com/TestFolder/images and also just as TestFolder/images

    and when I click to view the page all I get is.........
    $filename
    \n"; } ?>

    Is there something else I need to change within the code? I keep getting this same thing on the page every time I try to view


    Thanks!!

    Jacki

  • #10
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    If you want to run PHP in your page you need to use a .php file extension. Change your file name from new_page_1.htm to new_page_1.php
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #11
    New Coder
    Join Date
    Aug 2006
    Location
    Southeast Texas
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Spookster!

    Apparently I am more of an idiot that I first thought... I did as you said... Now the page is completely blank

    http://wickdimpressions.com/TestFolder/phptestpage.php

    Got rid of the error... But not sure what I should do now?

    Does the HTML codes get added to this page.. ?

    I'm confused (again)

    Sorry



    Jacki

  • #12
    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
    "yourdir/*.jpg" should be the relative path to the directory you want to list. You are running phptestpage.php out of TestFolder-- where is your images directory in relation to that? If it is TestFolder/images then you just want to use "images/*.jpg".

  • #13
    New Coder
    Join Date
    Aug 2006
    Location
    Southeast Texas
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "Test Folder" Is the folder the images are in so I did this code


    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <?php
    $images = glob("TestFolder\*.jpg");
    foreach($images as $fileName) {
    print "<a href=\"TestFolder\$filename\">$filename</a><br />\n";
    }
    ?>
    </body>
    </html>

    There are no subdirectories within "TestFolder"... I've been building webpages for just about 3 years now... Nothing professional or anything.. Just for friends, family. But I've never dealt with PHP, CGI, ASP etc... I thought since I knew HTML that learning PHP would be a breeze.. I was wrong LOL.... Well I can create forms with PHP.. but not this...

    With this PHP code.. Is this the ONLY code I need to know or have to do what I need it to do? Do I have to create other pages besides the PHP file with the code? Can I add HTML into the PHP file?

    Something is still wrong.. It just wont work for me!
    I appreciate the help though, and you being so patient with me..

    I've been reading tons of info on PHP, haven't slept in just over 24 hours now... ANd this one code just won't work... I know there is something I'm missing or just not doing right but can't put my finger on it!

    Thanks again for the help (hopefully I can get this to work some time soon... I've spent 3 days trying to figure this out... and haven't done any work in that time.. Luckily I can't fire myself lol) If I can't figure this out soon I may just need to get started on adding the links one by one.. boring!



    Jacki

  • #14
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    It looks like it is just a case-sensitive typo. Change $fileName to $filename.

    If that still doesn't work, we'll look at the path more closely but it appears to be correct at first glance.

    PHP Code:
    <html>
    <head>
    <title>PHP Test</title>
    </head>
    <body>
    <?php
    $images 
    glob("TestFolder\*.jpg");
    foreach(
    $images as $filename) {
    print 
    "<a href=\"TestFolder\$filename\">$filename</a><br />\n";
    }
    ?>
    </body>
    </html>

  • #15
    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
    If your images are in the same folder the php file is in then don't even specify a folder-- just use "*.jpg". That is assuming the images all have a jpg extension.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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