SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Addict mh8759's Avatar
    Join Date
    Jun 2000
    Location
    Slovenia, Europe
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I've made PHP script to store articles in database and then retrieve them. However, I want to store images too. Each HTML page, should have for instance 3 images. What's the simpliest way to use them in mysql ? I've tried storing filename path in column, however if I want to add 2 or more images I have to have 2 or more columns then.
    How have you done it on Sitepoint?

    I also want to make it available for my authors to attach their own images to the article. How can that(uploading files) be done in PHP?

    Thanks for your help
    Mare

  2. #2
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I haven't read them, but the title seems to fit your need.

    Storing pictures:
    http://www.phpbuilder.com/columns/florian19991014.php3

    PHP Uploading:
    http://www.phpbuilder.com/columns/bealers20000904.php3

    Hope they help.

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it what you really want to do (storing binary file in MySQL), or else you should just store the url/link to the image in MySQL, it's much more efficient.
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have done it with multiple images and storing the imagesnames and paths to one field, basically I created a || delimited string of the image names and store that. and to view them you just explode("||", $fieldfromdb);
    To get them into a nice array to work with then to delete images from you do the same but pop the image from the array implode it back togther then stick it back in the database, as for uploading the images you need the copy() function Check out the manual.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to store image paths then I suggest creating a separate table (Not using a || deliminated string) which has an ID column (which refers to the article/page id) an image descriptor (e.g. titleimage) and a column for the image url as this would follow good database design principals.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  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)
    Okay Okay so I don't always have the best ideas. But they work, Karl's is probably better.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do exactly the same as Freddy, I use a '|' delimited list of image urls as a field in the appropriate table, This way you can have a variable number of images per page without redundant imag1,image2 fields etc.

    If the site needs it, I also add the image descriptions in as well ,using a seperate delimiter.

    Which is more efficient depends greatly on the individual project.

  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)
    Sweet thanks for backing me up firepages
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    SitePoint Addict mh8759's Avatar
    Join Date
    Jun 2000
    Location
    Slovenia, Europe
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks everyone..you've been really helpful...
    I'll probably make new table for my images..thanks again..

    Mare

  10. #10
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't get me wrong freddy, it's not a bad idea and it's how I used to do the same job as well.

    Firepages, there will be no redundant image1, image2 etc. columns in any tables with my method as the table only has one field per row for an image url.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.


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
  •