Jump to content

retrieving images


bonito1

Recommended Posts

i have this script called view.php

<?php
  include 'db.inc';

  $file = clean($file, 4);

  if (empty($file))
     exit;

  if (!($connection = @ mysql_pconnect($hostName,
                                       $username,
                                       $password)))
     showerror();

  if (!mysql_select_db("Php_test", $connection))
     showerror();

  $query = "SELECT mime, data FROM file 
            WHERE id = $file";

  if (!($result = @ mysql_query ($query,$connection)))
     showerror();  

  $data = @ mysql_fetch_array($result);

  if (!empty($data["data"]))
  {
    // Output the MIME header
     header("Content-Type: {$data["mime"]}");
    // Output the image
     echo $data["data"];
   }
?>

after i have db.inc

<?php

// These are the DBMS credentials
$hostName = "localhost";
$username = "root";
$password = "oxioxi";

// Show an error and stop the script
function showerror()
{
   if (mysql_error())
      die("Error " . mysql_errno() . " : " . mysql_error());
   else
      die("Could not connect to the DBMS");
}

// Secure the user data by escaping characters 
// and shortening the input string
function clean($input, $maxlength)
{
  $input = substr($input, 0, $maxlength);
  $input = EscapeShellCmd($input);
  return ($input);
}

?>

and i have my page witch part of it is  this

   <?php
  include 'db.inc';
  
  $query = "SELECT id, name, mime FROM file";

  if (!($connection = @ mysql_pconnect($hostName, 
                                    $username,
                                    $password)))
     showerror();

  if (!mysql_select_db("php_test", $connection))
     showerror();
        
  if (!($result = @ mysql_query ($query, $connection)))
     showerror();
?>
    <h1>Image database</h1> 


<?php 


  if ($row = @ mysql_fetch_array($result))
  {
?>

    <table>
    <col span="1" align="right">
    <tr>
       <th>Short description</th>
       <th>File type</th>
       <th>Image</th>

    </tr>
<?php
   do 
   {
?>
    <tr>
       <td><?php echo "{$row["name"]}";?></td>         
       <td><?php echo "{$row["mime"]}";?></td>
       <td><?php echo "<img src=\"view.php?file={$row["id"]}\">";?></td>
    </tr>
<?php
   } while ($row = @ mysql_fetch_array($result));
?>
    </table>
<?php
  } // if mysql_fetch_array()
  else
     echo "<h3>There are no images to display</h3>\n";
?>

i have do it right but for some reason it doesnt displays the pictures the type and the name are displayed normally but not the picture!! instead of them there are small icons of not existing pictures.. plz i want help i really need to do it

Link to comment
Share on other sites

the file view.php, at no point in that file do you attempt to put a value into the variable $file, so it is empty

 

a value for this is being passed via a query string in the other script here:

<?php echo "<img src=\"view.php?file={$row["id"]}\">";?></td>

 

so in view.php you need to grab that value being passed to it

so put this line at the top of view.php

<?php  include 'db.inc';  
$file = $_GET['file'];
$file = clean($file, 4);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.