Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: image manipulation php mysql blob type

  1. #1
    Join Date
    May 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default image manipulation php mysql blob type

    hello there! i got a question about blob mysql data.i have a button and on buttonclick i want to open a popup (and passing date parameter) and show some details and display a photo.if i try
    PHP Code:
    <?php
    if (isset($_GET['p'])){
       
    $temp_date=$_GET['p'];
       echo 
    "DATE : $temp_d <br>";
       
    $date_m=date('Y-m-d',strtotime($d));
       
    $connect=mysql_connect("localhost","user","pass")
       or die (
    "Check your server connection"); 
       
    $db_found mysql_select_db("mydb"$connect);
       
    $SQL "SELECT * FROM mytable
               WHERE date =date_m"
    ;
               
    $result mysql_query($SQL);
               
    $row=mysql_fetch_array($result);
               echo 
    "Details: $row[details]<br>";
               
    $content $row['image'];
               
    header('Content-type:image/jpg');
               echo 
    $content;       
    ?>


    its not working.if i try
    PHP Code:
    <?php
       $connect
    =mysql_connect("localhost","user","pass")
       or die (
    "Check your server connection"); 
       
    $db_found mysql_select_db("mydb"$connect);
       
    $SQL "SELECT * FROM mytable
               WHERE id=1"
    ;
               
    $result mysql_query($SQL);
               
    $row=mysql_fetch_array($result);
               echo 
    "Details: $row[details]<br>";
               
    $content $row['image'];
               
    header('Content-type:image/jpg');
               echo 
    $content;       
    ?>


    its shows my results.how to pass the parameter and show the results to ? and does anybody knows why it doesnt work with parameter passing ? tnx in advance

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    You need to provide more details. What, exactly, is "not working"? What happens when you run the code, and what should happen? Do you receive any error messages?


    just at a glance, you're trying to send headers after you've already echoed output to the browser.

    in addition, you're using several variable names that don't exist: e.g., you set $temp_date and then try to use $temp_d. if these variables are set elsewhere in your code, please make a note of it, otherwise it will confuse the troubleshooting process. It is best to post all of your code.

  3. #3
    Join Date
    May 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i ve tried a lot...and i see that if i use header to show image i cannot echo anything else. is that true ? it doesnt seem logical to me....i can show a picture but no messages ? is there any other way to show image and echo details together ??

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    sending "Content-type: image/jpg" tell the browser that you're sending a picture - not a page with a picture in it. if you want to send content as well, put the image into regular html markup:
    PHP Code:
    print '<p>'$row['details'] .'</p><img src="data:image/jpg;base64,'$row['content'] .'">';
    // (assuming $row['content'] holds the binary source for the image) 
    is there a reason you're saving the images themselves in your database? i've always found more practical to save the image as a file and simply save the url in the database.

    as for efficiency, printing the binary source saves an http request, but bloats the markup. it's okay for small, cacheable images, I guess.
    Last edited by traq; 06-01-2011 at 03:40 AM.

  5. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    In my experience databases tend to have a far smaller storage size than server storage. The largest I have seen for database storage is 1GB and regular hosting storage goes up to unlimited.
    To choose the lesser of two evils is still to choose evil. My personal site

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by james438 View Post
    In my experience databases tend to have a far smaller storage size than server storage...
    true also.

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Databases can be unlimited (although that's rare), but sometimes they are actually limited by the software-- I think 4GB is a common limit depending on the format of the drive used to store it. This is beyond any limit that your host may have.

    Regardless, it's not a good idea to save them directly to the database for a few reasons: most importantly 1) it's inefficient and will slow down your database; 2) they won't act as files so things like caching in the browser won't work and you'll waste bandwidth. It's also harder to back up your database (if there are a lot of images since it will be huge) and there's no reason NOT to store them as files-- since they work as files and you can store a path in the database, that's the common (and best) method. Your choice though.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    May 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    it just been more easy to put the image in the table;now i must worry about unigue filenames....dont decided yet ! tnx for replies thoough

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    When storing images from users, you can do a lot of things to avoid filename duplication: you can give each user a folder, you can add a user-id prefix to each filename (27-image.jpg), or you can not use filenames-- generate a random name (or use the current date or timestamp) and store the actual filename in the database.

    Think of the file system as a storage room, and the database as a catalog. But all of the details really depend on the system. Also, the specific details will become more important as your site grows. If your site never gets too big, then it may not matter how it's setup. But if you want a "perfect" system, imagine a site that stores 1,000,000 images. Then think about possible problems with the design.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    some CMSs use a file hash as the filename. The relationships (description, owner, etc.) are stored in the database. Using a hash also has the advantage that you can use the filename as a checksum (you can automatically tell if someone is uploading a file that already exists).

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
  •