Jump to content

PHP Images


j115

Recommended Posts

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

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

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

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

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

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.