SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Angry How to pull up pictures from database

    hey all i m working a site i m new learner of advance php so i get this
    Code PHP:
    <?php require_once('../Connections/MyCon.php'); ?>
    <?php
    // Load the common classes
    require_once('../includes/common/KT_common.php');
     
    // Load the tNG classes
    require_once('../includes/tng/tNG.inc.php');
     
    // Make a transaction dispatcher instance
    $tNGs = new tNG_dispatcher("../");
     
    // Make unified connection variable
    $conn_MyCon = new KT_connection($MyCon, $database_MyCon);
     
    // Start trigger
    $formValidation = new tNG_FormValidation();
    $tNGs->prepareValidation($formValidation);
    // End trigger
     
    //start Trigger_ImageUpload trigger
    //remove this line if you want to edit the code by hand 
    function Trigger_ImageUpload(&$tNG) {
      $uploadObj = new tNG_ImageUpload($tNG);
      $uploadObj->setFormFieldName("Filedata");
      $uploadObj->setDbFieldName("photo");
      $uploadObj->setFolder("../DB_images/");
      $uploadObj->setMaxSize(1500);
      $uploadObj->setAllowedExtensions("gif, jpg, jpe, jpeg, png");
      $uploadObj->setRename("auto");
      return $uploadObj->Execute();
    }
    //end Trigger_ImageUpload trigger
     
    //start Trigger_Redirect trigger
    //remove this line if you want to edit the code by hand
    function Trigger_Redirect(&$tNG) {
      $redObj = new tNG_Redirect($tNG);
      $redObj->setURL(KT_getFullUri());
      $redObj->setKeepURLParams(false);
      return $redObj->Execute();
    }
    //end Trigger_Redirect trigger
     
    // Make an insert transaction instance
    $ins_images = new tNG_insert($conn_MyCon);
    $tNGs->addTransaction($ins_images);
    // Register triggers
    $ins_images->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
    $ins_images->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
    $ins_images->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "FILES", "Filedata");
    $ins_images->registerConditionalTrigger("{GET.isFlash} != 1", "END", "Trigger_Redirect", 90);
    $ins_images->registerTrigger("AFTER", "Trigger_ImageUpload", 97);
    $ins_images->registerConditionalTrigger("{GET.isFlash} == 1", "ERROR", "Trigger_Default_MUploadError", 10);
    // Add columns
    $ins_images->setTable("images");
    $ins_images->addColumn("photo", "FILE_TYPE", "FILES", "Filedata");
    $ins_images->setPrimaryKey("id", "NUMERIC_TYPE");
     
    // Execute all the registered transactions
    $tNGs->executeTransactions();
     
    // Get the transaction recordset
    $rsimages = $tNGs->getRecordset("images");
    $row_rsimages = mysql_fetch_assoc($rsimages);
    $totalRows_rsimages = mysql_num_rows($rsimages);
     
    // Multiple Upload Helper Object
    $muploadHelper = new tNG_MuploadHelper("../", 32);
    $muploadHelper->setMaxSize(1500);
    $muploadHelper->setMaxNumber(0);
    $muploadHelper->setExistentNumber(0);
    $muploadHelper->setAllowedExtensions("gif, jpg, jpe, jpeg, png");
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
    <script src="../includes/common/js/base.js" type="text/javascript"></script>
    <script src="../includes/common/js/utility.js" type="text/javascript"></script>
    <script src="../includes/skins/style.js" type="text/javascript"></script>
    <?php echo $tNGs->displayValidationRules();?><?php echo $muploadHelper->getScripts(); ?>
    </head>
     
    <body>
    <?php
    	echo $tNGs->getErrorMsg();
    ?>
    <?php
    // Multiple Upload Helper
    echo $tNGs->getSavedErrorMsg();
    echo $muploadHelper->Execute();
    ?>
    </body>
    </html>
    now all good this is working but how do i pull up the image into the page where it need to show up. any help?

  2. #2
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you're using a custom class, and want to select the image path in the database to print '<img>' out? Could you post the code for the class you're using?
    Cross browser css bugs

    Dan Schulz you will be missed

  3. #3
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thats what i made using developer extension in dreamweaver. i want to learn how to upload and retrieve image/documents. anyways which class u want me to paste?

  4. #4
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I'm a little confused.

    now all good this is working
    Does this mean you have just the upload working, and now you need to retrieve the image/documents?

    I assumed you were using a class for the db interaction.
    Cross browser css bugs

    Dan Schulz you will be missed

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,147
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    Do you have a table set up in a database?

  6. #6
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    well i dont have anything to retrieve images from database coz i don't know how to echo em

  7. #7
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All you'd need to do is extract results which are just file paths, for example

    $result = array('images/foo.gif');

    foreach ($result as $foo ) {
    echo '<img src="', $foo, '" alt="">';
    }
    Cross browser css bugs

    Dan Schulz you will be missed

  8. #8
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    can u be kind enuff and point me to a good tutorial on storing and retrieving images from database

  9. #9
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you need to alter the table to include an image column, is that it? There's nothing really special and the simple way is to just store the string, not the actual image as a blob ( unless you have multiple servers ). Just think of it the same as any other column, nothing special.
    Cross browser css bugs

    Dan Schulz you will be missed

  10. #10
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    well i did made a database eariler n set its type to longblob and i stored the image. the problem is that i wanna call on the image where it shld be display. like i wanna echo it from database on the page. but how


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
  •