phpNOvice Posted May 28, 2014 Report Share Posted May 28, 2014 (edited) 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 May 28, 2014 by phpNOvice Quote Link to comment Share on other sites More sharing options...
falkencreative Posted May 28, 2014 Report Share Posted May 28, 2014 At least for me personally, I'd suggest storing the file name of the image file in the database, rather than storing the file itself. Quote Link to comment Share on other sites More sharing options...
administrator Posted May 30, 2014 Report Share Posted May 30, 2014 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 Quote Link to comment Share on other sites More sharing options...
phpNOvice Posted May 30, 2014 Author Report Share Posted May 30, 2014 (edited) 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 May 30, 2014 by phpNOvice Quote Link to comment Share on other sites More sharing options...
administrator Posted May 31, 2014 Report Share Posted May 31, 2014 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 Quote Link to comment Share on other sites More sharing options...
phpNOvice Posted June 1, 2014 Author Report Share Posted June 1, 2014 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. Quote Link to comment Share on other sites More sharing options...
phpNOvice Posted June 10, 2014 Author Report Share Posted June 10, 2014 (edited) 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 June 10, 2014 by phpNOvice 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.
Note: Your post will require moderator approval before it will be visible.