Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    12

    Unanswered: Retrieving Image Location in MySQL

    Dear all,

    I have been trying to retrieve the location of a image from database and display the image in the browser using PHP. I have written a sort of code for the purpose. All I am getting in my browser after using the code is a long set of ASCII characters with the following warning
    *Warning*: Cannot modify header information - headers already sent by (output started at C:\wamp\www\mysqli.php:65) in *C:\wamp\www\mysqli.php* on line *237
    *
    I am herewith attaching my code. If anyone can point out the error or give some kind of advice that would be really great. The location of the image is stored in a table by the name IMAGE under the column name Location and here in the code, the location is retrieved under the varibale name $Location.

    thanks,
    Sashi

    Code:
    <html>
    <body>
    <form action="mysqli.php" method="post">
    <br>
    <div align="center">
    Building Name:<select name="name">
    <option value=""> Select a Building</option>
    <option value="Agnew Hall">Agnew Hall</option>
         <option value="Rector Field House">Rector Field House</option>
         <option value="Richard B. Talbot Educational Resources Center">Richard B. Talbot Educational Resources Center</option>
         <option value="Robeson Hall">Robeson Hall</option>
         <option value="Sandy Hall">Sandy Hall</option>
         <option value="Saunders hall">Saunders hall</option>
         <option value="Seitz Hall">Seitz Hall</option>
         <option value="Shanks Hall">Shanks Hall</option>
         <option value="Shultz Hall">Shultz Hall</option>
         <option value="Skelton Conference Center">Skelton Conference Center</option>
         <option value="Williams Hall">Williams Hall</option>
         <option value="Women's Softball Field">Women's Softball Field</option>
         <option value="Wright House">Wright House</option>
    </select>
    </div>
                       <input type="submit" />
    </form>
    <img src="mysqli.php?">
    
    <?php
    // Connects to your Database
    $host="*******";
    $user="*****";
    $password="******";
    $dbname="*******";
    $cxn=mysqli_connect($host, $user, $password, $dbname) ;
    if (!$cxn=mysqli_connect($host, $user, $password, $dbname))
       {
           $error=mysqli_error($cxn);
           echo "$error";
           die();
       }
    else
       {
           echo "Connection established successfully";
       }
    //Define the variables for Day and Month
    $Today=date("l");
    $Month=date("F");
    $build=$_POST["name"];
    $low_speed=2.5;
    $high_speed=4;
    $hour=date("G");
    $minute=date("i");
    if ($minute>=00 && $minute<=14)
       {
           $minute=00;
       }
    elseif ($minute>=15 && $minute<=29)
       {
           $minute=15;
       }
    elseif ($minute>=30 && $minute<=44)
       {
           $minute=30;
       }
    else
       {
           $minute=45;
       }
    $times="$hour:$minute";
    $sql="SELECT buildingname, parking_lot_name, empty_spaces, distance, round(distance/($low_speed*60),1) AS low_time, round(distance/($high_speed*60),1) AS high_time, Location FROM buildings, buildings_lots, parkinglots, occupancy2, Image where (buildings.buildingcode=occupancy2.building AND  buildings.buildingcode=buildings_lots.building_code AND parkinglots.parking_lot_code=buildings_lots.parking_lot_code AND parkinglots.parking_lot_code=occupancy2.parking_lot AND Buildings.BuildingCode=Image.BuildingCode) AND buildingname='$build' AND month='$Month' AND day='$Today' AND Time='$times'";
    $data = mysqli_query($cxn,$sql);
    if (!$data=mysqli_query($cxn,$sql))
       {
           $error=mysqli_error($cxn);
           echo "$error";
           die();
       }
    else
       {
           echo "<br>";
           echo "Query sent successfully";
       }
    echo "<br>";
    echo "<h1> PARKING LOT INFORMATION <h1>";
    echo "<table border='1' cellspacing='5' cellpadding='2'>";
    echo "<tr>\n
           <th>Building</th>\n
           <th>Parking Lot</th>\n
           <th>Estimated Number of Empty Spaces</th>\n
           <th>Distance (Feet)</th>\n
           <th>Estimated walking time to the building</th>\n
       </tr>\n";
    while ($row=mysqli_fetch_array($data))
       {
           extract($row);
    $building = $row[0];
         $parking_lot = $row[1];
         $Number_of_Empty_Spaces = $row[2];
         $Distance = $row[3];
         $time_l = $row[4];
         $time_h=$row[5];
         $location=$row[6];   echo "<tr>\n
                 <td>$building</td>\n
                 <td>$parking_lot</td>\n               <td>$Number_of_Empty_Spaces</td>\n
                 <td>$Distance</td>\n
                 <td>$time_h - $time_l mins</td>\n
    <td>$location</td>\n
                 </tr>\n";
       }
       echo "</table>\n";
    $err=1;
    if ($img = file_get_contents($location, FILE_BINARY))
    {
     if ($img = imagecreatefromstring($img)) $err = 0;
    }
    if ($err)
    {
     header('Content-Type: text/html');
     echo '<html><body><p style="font-size:9px">Error getting image...</p></body></html>';
    }
    else
    {
     header('Content-Type: image/jpeg');
     imagejpeg($img);
     imagedestroy($img);
    }
    ?>
    </body>
    </html>

  2. #2
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    You CANNOT do

    header('Content-Type: text/html');
    or
    header('Content-Type: image/jpeg');

    If you have already output (i.e. echo'd) some content. Headers MUST be sent before any output. The error indicates this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •