mark103 Posted July 23, 2011 Share Posted July 23, 2011 Hi guys, I need your help. I am using two scripts as one are using for to hotlink the images that I have stored in mysql and the other script i am using for to get access to images.php. The two scripts I am using is link.php and images.php. I have got a problem with the images as I am trying to extact them when I enter the url something like www.mysite.com/link.php?user=test. I can't be able to extact the images when I get access to images.php and input the images in my php page. The image data have displayed as empty array. here's the screenshot: Link.php <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'root'); define('DB_PASSWORD', ''); define('DB_DATABASE', 'hf'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var) { return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $pass = clean($_GET['pass']); if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />', $errmsg_arr); } else { $insert = array(); if(isset($_GET['user'])) { $insert[] = 'username = \'' . clean($_GET['user']) .'\''; } if(isset($_GET['pass'])) { $insert[] = 'pass = \'' . clean($_GET['pass']) . '\''; } if (count($insert)>0) { $names = implode(',',$insert); if($username) { $sql = 'SELECT `id` FROM `images_list` WHERE `username` = "'.$username.'"'; $result1 = mysql_query($sql) or die('Error:<br />'. $sql .'<br />' . mysql_error()); $res = mysql_fetch_assoc($result1); foreach($res as $row) { echo '<p id="images"><img src="images.php?id='. $row['id'] .'" /></p>'; } } } } Images.php <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $id = (int)$_GET['id']; $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var) { return mysql_real_escape_string(strip_tags($var)); } $sql = 'SELECT `images` FROM `Images_list` WHERE `id` = "'. $id .'"'; $result1 = mysql_query($sql) or die('Error:<br />'. $sql .'<br />' . mysql_error()); $res = mysql_fetch_assoc($result1); foreach($res as $row) { var_dump($row['images']); exit; $details = getimagesize($row['images']); header ('Content-Type: ' . image_type_to_mime_type($details[2])); echo file_get_contents($row['images']); } ?> any idea how to fix this? Quote Link to comment Share on other sites More sharing options...
dcro2 Posted July 23, 2011 Share Posted July 23, 2011 Try visiting the source of the image directly. Most likely, one of your error outputs in images.php is making a corrupt image. Since the browser is expecting to display an image inside the <img>, it just thinks it's broken. So, again, view the source of link.php in your browser and visit whatever it has output as the src of the image. For example, 'images.php?id=123'. Then you'll be able to see any errors your script encountered. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.