#1
  1. No Profile Picture
    SWiTCH2
    Guest
    Devshed Newbie (0 - 499 posts)
    Hi,
    I'm planning on letting my users add pictures to their pages using the browser upload method.
    My question is, which is better? adding the picture to the database? or storing them on a separte directory and add a link to the page?
    I also will be letting each user have quota on the disk space.
    Your thoughts and suggestions appreciated.

    Cheers!
  2. #2
  3. No Profile Picture
    wesb
    Guest
    Devshed Newbie (0 - 499 posts)
    Its usually best to store the picture as a file, and then store the location of that file in the database.

    ------------------
    wesb@devshed.com
    www.devshed.com
  4. #3
  5. No Profile Picture
    rtp
    Guest
    Devshed Newbie (0 - 499 posts)
    Along the lines of this thread: more questions.

    I've been able to configure my debian/linux server to use numerous php scripts including horde/imp, phorum etc., which are great apps that I love. I've gone through a number of tutorials and searched numerous archives for answers to my questions. At this point, I am confused enough to be considering renting all available Captain Kangaroo videos and ...

    My concerns are entering imgage file locations into a mysql database, extracting the correct data, associated by "id," and then displaying the php dynamically generated pages.

    The mysql database, table, column is a "varchar." My entry currently reads:
    images/test01.gif
    Is this the correct syntax for telling mysql where an image file is?

    I've attempted numerous self construed abominations to printing the appropriate image; including, seperate "printf" commands for the image files, two of which are commented out in the full script below.

    The following works perfectly for my text fields:

    <?php
    snip
    printf("<tr><td><a href="%s?id=%s">%s %s </a></td></tr
    ><br>n", $PHP_SELF, $myrow["id"], $myrow["first"], $myrow["last"]);
    snip
    ?>

    This is the full code for my script which is modified from the hotwire webmonkey tutorial "http://www.hotwired.com/webmonkey/99/21/index2a.html?tw=frontdoor":

    <?php

    include("class.layout");
    include("header.inc");


    $db = mysql_connect("localhost", "username", "passwd");

    mysql_select_db("mplsesc",$db);

    // display individual record

    if ($id) {

    $result = mysql_query("SELECT * FROM poets WHERE id=$id",$
    db);

    $myrow = mysql_fetch_array($result);

    printf("<P>Poet: %sn<br>", $myrow["thumbs"]);

    printf("<P>First name: %sn<br>", $myrow["first"]);

    printf("Last name: %sn<br>", $myrow["last"]);

    printf("E-mail: %sn<br>", $myrow["email"]);

    printf("HomePage: %sn<br>", $myrow["homepage"]);

    printf("Description: %sn<br>", $myrow["bio"]);

    printf("Availability: %sn<br>", $myrow["avail"]);


    } else {

    // no records to display

    echo "Sorry, no records were found!";

    }

    }

    include("footer.inc");
    ?>

    Sorry about writing a book. All help is appreciated and reciprocated.

    ron parker
    www.mi-recordz.com (Free services for all independent artists.)
    rtp@mi-recordz.com
  6. #4
  7. No Profile Picture
    rtp
    Guest
    Devshed Newbie (0 - 499 posts)
    whoops, chopped the code.

    I've been able to configure my debian/linux server to use numerous php scripts including horde/imp, phorum etc., which are great apps that I love. I've gone through a number of tutorials and searched numerous archives for answers to my questions. At this point, I am confused enough to be considering renting all available Captain Kangaroo videos and ...

    My concerns are entering imgage file locations into a mysql database, extracting the correct data, associated by "id," and then displaying the php dynamically generated pages.

    The mysql database, table, column is a "varchar." My entry currently reads:
    images/test01.gif
    Is this the correct syntax for telling mysql where an image file is?

    I've attempted numerous self construed abominations to printing the appropriate image; including, seperate "printf" commands for the image files, two of which are commented out in the full script below.

    The following works perfectly for my text fields:

    <?php
    snip
    printf("<tr><td><a href="%s?id=%s">%s %s </a></td></tr
    ><br>n", $PHP_SELF, $myrow["id"], $myrow["first"], $myrow["last"]);
    snip
    ?>

    This is the full code for my script which is modified from the hotwire webmonkey tutorial "http://www.hotwired.com/webmonkey/99/21/index2a.html?tw=frontdoor":

    <?php

    include("class.layout");
    include("header.inc");


    $db = mysql_connect("localhost", "username", "passwd");

    mysql_select_db("mplsesc",$db);

    // display individual record

    if ($id) {

    $result = mysql_query("SELECT * FROM poets WHERE id=$id",$
    db);

    $myrow = mysql_fetch_array($result);

    printf("<P>Poet: %sn<br>", $myrow["thumbs"]);

    printf("<P>First name: %sn<br>", $myrow["first"]);

    printf("Last name: %sn<br>", $myrow["last"]);

    printf("E-mail: %sn<br>", $myrow["email"]);

    printf("HomePage: %sn<br>", $myrow["homepage"]);

    printf("Description: %sn<br>", $myrow["bio"]);

    printf("Availability: %sn<br>", $myrow["avail"]);


    } else {

    // show list
    // show list

    $result = mysql_query("SELECT * FROM poets",$db);

    if ($myrow = mysql_fetch_array($result)) {

    // display list if there are records to display

    do {

    echo "<TABLE BORDER=1 >n";

    //printf ("$thumbs = file_exists("../images/thumbs/$id.jpg
    //") ? "<IMGSRC="/images/thumbs/$id.jpg">" : "No Photo //Yet<br>n", $PHP_SELF, $myrow["id"], $myrow["thumbs"] );

    printf("<tr><td><a href="%s?id=%s">%s %s </a></td></tr
    ><br>n", $PHP_SELF, $myrow["id"], $myrow["first"], $myrow["last"]);

    //printf ("<tr><td><img src="/images/$id.jpg"></td></tr>
    //<br>n", $PHP_SELF, $myrow["id"], $myrow["thumbs"] );

    echo "</TABLE>n";

    } while ($myrow = mysql_fetch_array($result));

    } else {

    // no records to display

    echo "Sorry, no records were found!";

    }

    }

    include("footer.inc");
    ?>

    Sorry about writing a book. All help is appreciated and reciprocated.

    ron parker
    www.mi-recordz.com (Free services for all independent artists.)
    rtp@mi-recordz.com

  8. #5
  9. No Profile Picture
    louisra
    Guest
    Devshed Newbie (0 - 499 posts)
    I was able to get this to work. I'm not looping them though. I'm including this in as <IMG SRC="<? include("imgmain.php3")?>">:

    <?php
    $rootpath = getenv("REQUEST_URI");
    $dirpath = dirname($full_path);
    $filename = basename($full_path);
    $filenum = substr($filename, strrpos($filename, "=") + 1);
    print "$dirpath/images/$filenum.jpg";
    printf("" ALT="%s", $row["title"]);
    ?>

    Is the lack of a space between IMG and SRC in your thumbnail code above a direct copy from your working files?

    [This message has been edited by louisra (edited 09-29-99).]
  10. #6
  11. No Profile Picture
    rtp
    Guest
    Devshed Newbie (0 - 499 posts)
    louisra,

    Thanks for sharing that code and your time. I am try to interpret what your code does and how to use your strategy or see from your example what I might be missing. This is all pretty new and takes some time for me to understand. Excellent, than you!

    The following printf produces the broken image icon and then the path statement, that's entered into the thumbs column of my database:

    printf ("<tr><td><img src="%s?id=%s">%s </td></tr>
    <br>n", $PHP_SELF, $myrow["id"], $myrow["thumbs"] );

    The result is the path "/home/will/www/images/thumbs/test01.jpeg" printed to the html page with and a broken image icon.

    I was wondering if my problem is not knowing how to correctly enter the file location within the database thumbs column. Does it require the full path or is it still something else?

    If I can get the image to print then I won't worry about "file_exists" until a later time. This isn't a huge application with alot of changes so I can do some by hand. The printf with the file_exists is where you caught my typo.
  12. #7
  13. No Profile Picture
    rycamor
    Guest
    Devshed Newbie (0 - 499 posts)
    There is a simplistic answer to the above that does NOT require that the database store any info about the image directly. I simply save the image AS the id number for that record, and call it with something like:

    echo "<img src='thumbs/$id'>"

    For example, the following script calls a recordset as an array, and loads the appropriate thumbnail image for each record automatically:

    $db = mysql_connect("localhost", "webuser", "");

    $query = "SELECT id, first, last, address, position FROM employees";

    $result = mysql_db_query("mydb", $query);

    if ($result) {
    echo "Found these entries in the database:<ul>";
    while ($r = mysql_fetch_array($result)) {
    $id = $r["id"];
    $first = $r["first"];
    $last = $r["last"];
    $address = $r["address"];
    $position = $r["position"];
    echo "<li><a href='imgdetail.php3?id=$id'><img src='thumbs/$id'></a> $first $last; $address; <b>$position</b>";
    }
    echo "</ul>";
    } else {
    echo "No data.";
    }
    mysql_free_result($result);
    ?>

    HINT: you don't even need to add .gif or .jpg to the name of your image, just save it without an extension. The browser will just assume it's a standard web image and load it. Also, if you are afraid of having a "broken link" icon appear if there is no picture, you can either have PHP check for a file first or even more simply, have a standard image "picture not available" which can be replaced anytime by the user's image.

Similar Threads

  1. MySQL Access through External Sources
    By andyjamison in forum MySQL Help
    Replies: 1
    Last Post: February 17th, 2004, 07:02 AM
  2. From Access to remote MySQL
    By TimMatthews in forum Database Management
    Replies: 0
    Last Post: February 3rd, 2004, 09:54 AM
  3. Replies: 0
    Last Post: January 30th, 2004, 08:46 PM
  4. database type: mySQL, MS SQL and Access
    By vinyl in forum ColdFusion Development
    Replies: 5
    Last Post: January 27th, 2004, 07:25 PM
  5. MySQL Access from SUN ONE
    By meyerc75 in forum MySQL Help
    Replies: 5
    Last Post: January 24th, 2004, 01:23 PM

IMN logo majestic logo threadwatch logo seochat tools logo