j115 Posted September 29, 2008 Share Posted September 29, 2008 I have a question about PHP Picture Hosting. I am creating a php interface for image hosting. Is it possible to make something so like to get a certain image I would do the following: Say I am hosting 2 Pictures, I Go To :http://www.whatever.com/picture.php?do=1 It Shows: Picture 1 I Go To :http://www.whatever.com/picture.php?do=2 It Shows: Picture 2 Is this possible, if so, how can I do this? Link to comment https://forums.phpfreaks.com/topic/126216-php-images/ Share on other sites More sharing options...
teynon Posted September 29, 2008 Share Posted September 29, 2008 Yes. Store image data in a blob in the database or read the file contents of it. Use the id to call that blob and display it with a proper heading: header ('Content-type: image/jpeg'); Link to comment https://forums.phpfreaks.com/topic/126216-php-images/#findComment-652676 Share on other sites More sharing options...
j115 Posted September 29, 2008 Author Share Posted September 29, 2008 Yes. Store image data in a blob in the database or read the file contents of it. Use the id to call that blob and display it with a proper heading: header ('Content-type: image/jpeg'); Thanks for the quick reply! I am new to PHP and MySQL. Could you explain how to do this? Thanks! Link to comment https://forums.phpfreaks.com/topic/126216-php-images/#findComment-652678 Share on other sites More sharing options...
The Little Guy Posted September 29, 2008 Share Posted September 29, 2008 just save the file as you normally would, then read in the file when you access it. http://mysite.com/file.php?id=1 Do something like this: $id = $_GET['id']; if(!is_numeric($id)){ echo 'Bad File'; }else{ $sql = mysql_query("SELECT fileName,ext FROM tableName WHERE id = '$id'"); if(mysql_num_rows($sql) > 0){ $row = mysql_fetch_array($sql); if($row['ext']=='jpg') header('Content-type: images/jpeg'); if($row['ext']=='gif') header('Content-type: images/gif'); if($row['ext']=='png') header('Content-type: images/png'); readfile('location/of/images/'.$row['fileName']); } } Link to comment https://forums.phpfreaks.com/topic/126216-php-images/#findComment-652684 Share on other sites More sharing options...
The Little Guy Posted September 29, 2008 Share Posted September 29, 2008 Oh... some sites block linking to files that are not an image, such as a PHP file, but that outputs a an image, so this method will NOT work on those sites... MySpace is one of them. Link to comment https://forums.phpfreaks.com/topic/126216-php-images/#findComment-652689 Share on other sites More sharing options...
j115 Posted September 29, 2008 Author Share Posted September 29, 2008 just save the file as you normally would, then read in the file when you access it. http://mysite.com/file.php?id=1 Do something like this: $id = $_GET['id']; if(!is_numeric($id)){ echo 'Bad File'; }else{ $sql = mysql_query("SELECT fileName,ext FROM tableName WHERE id = '$id'"); if(mysql_num_rows($sql) > 0){ $row = mysql_fetch_array($sql); if($row['ext']=='jpg') header('Content-type: images/jpeg'); if($row['ext']=='gif') header('Content-type: images/gif'); if($row['ext']=='png') header('Content-type: images/png'); readfile('location/of/images/'.$row['fileName']); } } Would this save any space on my website? Link to comment https://forums.phpfreaks.com/topic/126216-php-images/#findComment-652701 Share on other sites More sharing options...
The Little Guy Posted September 29, 2008 Share Posted September 29, 2008 Would this save any space on my website? What do you mean? if you place this in a database, or on your site, it will take up space, and both ways will take up the same amount of space. My version allows for two ways to access the file: 1. Directly example: http://mysite.com/images/imageName.jpg 2. Through a PHP file example: http://mysite.com?id=123 The other way you can ONLY access it through the second example Link to comment https://forums.phpfreaks.com/topic/126216-php-images/#findComment-652703 Share on other sites More sharing options...
Andy17 Posted September 29, 2008 Share Posted September 29, 2008 1. Directly example: http://mysite.com/images/imageName.jpg 2. Through a PHP file example: http://mysite.com?id=123 The other way you can ONLY access it through the first example Just a small typo. Link to comment https://forums.phpfreaks.com/topic/126216-php-images/#findComment-652778 Share on other sites More sharing options...
The Little Guy Posted September 29, 2008 Share Posted September 29, 2008 1. Directly example: http://mysite.com/images/imageName.jpg 2. Through a PHP file example: http://mysite.com?id=123 The other way you can ONLY access it through the first example Just a small typo. no I was correct, if it is stored in the data base you can only access it from my second example. Link to comment https://forums.phpfreaks.com/topic/126216-php-images/#findComment-652779 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.