Guest Posted February 1, 2007 Share Posted February 1, 2007 I want to use a php file to record in a database how many time a image has been loaded. I can get the recording but then how would i display the image using that php file. Link to comment https://forums.phpfreaks.com/topic/36692-image-counting/ Share on other sites More sharing options...
Daniel0 Posted February 1, 2007 Share Posted February 1, 2007 You could do something like this. Name your file something like: <?php /* Database structure: -------------------------------- | id | mime | filename | views | -------------------------------- */ $config = array( 'db_host' => "localhost", 'db_user' => "root", 'db_pass' => "", 'db_name' => "your_database", 'image_path' => "/home/somebody/images/", // needs trailing slash! ); $db_link = @mysql_connect($config['db_host'], $config['db_user'], $config['db_pass']); @mysql_select_db($config['db_name'], $db_link) or die(); $query = @mysql_query("SELECT * FROM images WHERE id='".intval($_GET['image_id'])."' LIMIT 1", $db_link); if(@mysql_num_rows($query) <= 0) { die(); } else { $image_info = @mysql_fetch_assoc($query); @header("Content-type: {$image_info['mime']}"); @readfile($config['image_path'].$image_info['filename']); } @mysql_close($db_link); ?> Link to comment https://forums.phpfreaks.com/topic/36692-image-counting/#findComment-175010 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.