bonito1 Posted April 19, 2011 Share Posted April 19, 2011 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 https://forums.phpfreaks.com/topic/234189-retrieving-images/ Share on other sites More sharing options...
spiderwell Posted April 19, 2011 Share Posted April 19, 2011 is view.php missing $file = $_GET['file'] ? Link to comment https://forums.phpfreaks.com/topic/234189-retrieving-images/#findComment-1203706 Share on other sites More sharing options...
requinix Posted April 19, 2011 Share Posted April 19, 2011 So is the database called "php_test" or "Php_test"? Link to comment https://forums.phpfreaks.com/topic/234189-retrieving-images/#findComment-1203718 Share on other sites More sharing options...
bonito1 Posted April 20, 2011 Author Share Posted April 20, 2011 it is php_test but it isnt that it makes the difference ..any other ideas? Link to comment https://forums.phpfreaks.com/topic/234189-retrieving-images/#findComment-1203917 Share on other sites More sharing options...
bonito1 Posted April 20, 2011 Author Share Posted April 20, 2011 is view.php missing $file = $_GET['file'] ? cant understand what r you saying can you explain? Link to comment https://forums.phpfreaks.com/topic/234189-retrieving-images/#findComment-1203919 Share on other sites More sharing options...
spiderwell Posted April 20, 2011 Share Posted April 20, 2011 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 https://forums.phpfreaks.com/topic/234189-retrieving-images/#findComment-1203922 Share on other sites More sharing options...
bonito1 Posted April 21, 2011 Author Share Posted April 21, 2011 thanx very useful:) Link to comment https://forums.phpfreaks.com/topic/234189-retrieving-images/#findComment-1204668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.