Hello Daniweb,,

I have uploaded an image using the student_id as its filename. The student id is auto-incremented and unique per student_id. Now i am confused why it gives me problem to display it. I have tried.

  <?php print '<img src="uploads/'.$session_id.'" />' ?>

  <?php print '<img src="uploads/'.$session_id.".".$ext'" />' ?>

  <?php print '<img src="uploads/'.$student_id.'" />' ?>

  <img src='uploads/".$actual_image_name."' class='profile-photo' align="middle"> //where $actual_image_name = $student_id.".".$ext;

but still the image wont display

Edited by hanspeare_1: arrange codes

2 Years
Discussion Span
Last Post by hanspeare_1

<?php print '<img src="uploads/'.$session_id.".".$ext'" />' ?>

A file extension would be a good idea, so assuming (as @pirateas has said) $session_id = $student_id, and you have an image saved in uploads/{student_id}.{extension}, all of that looks fine.


Are you sure that you're referencing the uploads directory properly? Is uploads a directory in the same directory as the page you're on? Try modifying to display a hardcoded image...

<?php print '<img src="uploads/836.jpg" />' ?>

i.e. one that you know exists in the directory. Sorry perhaps that's too simplistic. There can be issues, especially if you're using apache mod_rewriting. If so you may need to have a list of exempt directories from your rewriting.



i think to answer better your queries is to give you my upload.php. This is a succesful page that when the user click the upload button the image will automatically display on same page temporarily and renamed to the unique student_id.

    $session_id = $_SESSION['user_id'];
    if($session_id == null){
    include 'Connect.php';
    $flag = "";
    $result = mysql_query("SELECT * FROM student_information where student_id='{$_SESSION['user_id']}'",$link_id);;
    $data = mysql_fetch_array($result);

---some html, javascript and style codes here

$path = "uploads/";
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
list($txt, $ext) = explode(".", $name);
if($size<(1024*1024)) // Image size max 1 MB
$session_id = $student_id.".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name))
mysql_query("UPDATE student_information SET profile_image='$actual_image_name' WHERE student_id='{$_SESSION['user_id']}'",$link_id);
echo "<img src='uploads/".$session_id."' class='preview'>";
echo "failed";
echo "Image file size max 1 MB"; 
echo "Invalid file format.."; 
echo "Please select image..!";
<div style="width:600px">
<form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php'>
Change your profile pic <input type="file" name="photoimg" id="photoimg" />
<div id='preview'>


Now my problem is to display the codes on the other page.



after i uploaded the image it displays automatically on the same page and the filename will be rename to its student_id (the one who uploads or log in)

i have followed your suggestion by directly referring the filename of the uploaded image and whew!!! it works and the image displays.

i am very interested in your statement to modify my codes in regards to this kind of apache situation. please be kind to modify my codes.



sorry if i ask you for that, if in any case, is there any way that someone could give me the codes, a donation or so?
is it still possible to display the uploaded image to other page?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.