Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

database has just image filenames, code to point to the path for images folder

Options
  • 23-07-2012 12:10am
    #1
    Registered Users Posts: 763 ✭✭✭


    I have searched for this solution on google without success, maybe someone can help me.

    Bought a Gallery and it already has a mysql database so people can upload photos through the backend. I want to use that database (or specific table with images) to show dynamic images throughout the website I designed on other pages.

    It is a website with products.

    This is the code(from a recordset) I used to test a dynamic image from the gallery database on another .php page:

    images/<?php echo $row_Recordset1[‘ImageName’]; ?>

    The database has just the image filenames with no path to each image file. I think that this is a much better way instead of putting a path into the database such as images/photo1 or typing images/ before every dynamic image I want to use.

    What code would I need to insert on a page to point to the images folder so I didn’t have to insert images/ into the code for every dynamic image?

    Many thanks.


Comments

  • Registered Users Posts: 2,228 ✭✭✭techguy


    You need to set a global reference in your site that points to the images root directory.

    Then just prepend that to: $row_Recordset1[‘ImageName’]

    Do you have PHP experience?

    Whats the gallery product you bought? Link?


  • Registered Users Posts: 763 ✭✭✭EIREHotspur


    Thanks for the reply.

    This is the gallery.

    http://codecanyon.net/item/sleek-gallery/231637

    The author simply said "You may take a look at function getImage()"

    Very little experience with PHP and thats why Dreamweaver extensions and scripts that I can buy and work through and adapt are the way to go for me.

    EDIT
    Ok I googled your advice and got this link
    http://www.londatiga.net/it/how-to-define-global-absolute-path-in-php/
    Variables is how it is done?.

    Based on above For example if you had your images in media/images in your root directory and just filenames in a field in a mysql database what would your global reference code for your images be?


  • Registered Users Posts: 2,228 ✭✭✭techguy


    The global is a relative path to the "media/images" folder, by relative I mean relative to where the PHP Gallery script is running.

    Example:

    Imagine the PHP gallery is running as a script (.php file) in the folder "website" and the "media" folder also resides in this folder. A relative link to the "images" folder is simply "media/images".

    If you post the directory structure of the script then I should be able to help a little better.


  • Registered Users Posts: 763 ✭✭✭EIREHotspur


    Thanks for that.

    I'd prefer to have a general example because I would use that instead of the script as there are a few drawbacks to the gallery.

    I usually do my websites in the following

    root
    - media/images

    I put most of my pages in the root as in index.php, aboutus.php, gallery.php etc.

    I uploaded photos to the server images folder using their upload and they sit in the folders they named:
    media\gallery\photo\large
    media\gallery\photo\thumb

    I then copied their mysql database and copied all of the photos to images/ to test out.
    Like I said I created a recordset:
    images/<?php echo $row_Recordset1[‘ImageName’]; ?>
    It put the first photo on the page but of course didn't work without images/ being inserted before it and didn't work with a repeat region either.

    I just want to be able to insert the global path to the images folder in php so that I can display images from a database like any other data.

    thanks for that.


Advertisement