Jump to content
Killersites Community
Sign in to follow this  
phpNOvice

Display Image Of A Specific Student

Recommended Posts

Hello there Admins,

 

I would like to display the image on his/her profile. This is so far the codes i have made. It displays only the outline border of the image but not the student's image itself.

<?php
	session_start();
	$session_id = $_SESSION['admin_id'];
	if($session_id == null){
	   header("location:Admin_Home.php");
	   die();
	}
   
    include 'Connect.php';
    $student_id = htmlentities($_REQUEST['id'], ENT_QUOTES);
    $result = mysql_query("SELECT * FROM student_information where student_id='$_GET[id]'");
    $data = mysql_fetch_array($result);
    $numRows = mysql_numrows($result);
    $i = 0;
    
    while($i < $numRows)  {
?>
         <img src="display_image.php?id=<?php echo mysql_result($data,$i,"id"); ?>" width="175" height="200" 
     <?php
	$i++;
	}
     ?> 

Please advise me how to modify these codes to make the image display.

 

By the way this is the display_image.php i created.

<?php 
    include 'Connect.php';
 	$flag = "";
    $student_id = htmlentities($_REQUEST['id'], ENT_QUOTES);
 
if (IsSet($_GET['id'])){
$result = @mysql_query("select * from student_information where student_id = ".$_GET['id']);
header("Content-type: image/jpeg");
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Type: PHP Generated Data");
header("Content-Length: ".filesize($filename));

while ($data = mysql_fetch_array($result))
{
print $data['LRCard'];}
mysql_free_result($result);
}
?>
Edited by phpNOvice

Share this post


Link to post
Share on other sites

Yep. Blob data is very heavy and should generally not be stored in databases. Just store a link/path/reference to your images which would be stored directly on the server - in the file system itself.

 

Stef

Share this post


Link to post
Share on other sites

I have uploaded the specific image of the student in

 

xampp/htdocs/a/images

 

and i want to display it specifically on their profile given their unique id.

 

I really think there is something missing in my codes maybe the path but i just dont know how to express it.

 

Please advise

 

Note: "images" is a folder where all the image of the students are saved.

Edited by phpNOvice

Share this post


Link to post
Share on other sites

As the images are uploaded to the server (I assume using a web interface) you should rename the images (according to the profileID) to avoid name collisions should someone else try to upload an image of the same name. Then you should store that image name in the database where you can use this to build the path to the image in your pages. 

 

Now, if the  images are renamed to the profileID, then in theory you don't have to store any image reference in the database since you could just use the profileID combined with the image directory to find your images. 

 

... Depends on the needs of your project.

 

Stef

Share this post


Link to post
Share on other sites

Wow Stef,,

 

Why did i never thought of that,,i'll debug my codes later to change image name to its id(on the upload page codes)..see if i can work it..

 

I'll update you soon. Thank you for the idea.

Share this post


Link to post
Share on other sites

Hello Admin,

 

This is my upload code

if($result){
			if($_FILES['image']['name'] != ""){
				$filename = $_FILES['image']['name'];
				$ext = strrchr($filename,".");
				$imagename = $student_id;
				if($ext ==".jpg" || $ext ==".jpeg" || $ext ==".JPG" || $ext ==".JPEG" || $ext ==".gif" || $ext ==".GIF"){
					$size = $_FILES['image']['size'];
					if($size > 0 && $size < 5000000){
						$archive_dir = "images";
						$userfile_tmp_name = $_FILES['image']['tmp_name'];
						if(move_uploaded_file($userfile_tmp_name, "$archive_dir/$imagename"))

and the image is successfully uploaded to

 

xampp/htdocs/a/images

 

 

 

 you should rename the images (according to the profileID) 

with the student id (not the unique number) is the file name.

 

The same codes for display_image.php and the student_view.php as shown above.

But still no luck the image still broken.

 

Please advise.

Edited by phpNOvice

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×