0

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

4
Contributors
7
Replies
34
Views
2 Years
Discussion Span
Last Post by hanspeare_1
0

<?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.

0

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.

0

@pritaeas
@mattster

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.

<?php
    session_start();
    $session_id = $_SESSION['user_id'];
    if($session_id == null){
       header("location:Student_Edit.php");
       die();
    }
    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

<?php
$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'];
if(strlen($name))
{
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats))
{
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'>";
}
else
echo "failed";
}
else
echo "Image file size max 1 MB"; 
}
else
echo "Invalid file format.."; 
}
else
echo "Please select image..!";
exit;
}
?>
<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" />
</form>
<div id='preview'>
</div>  

</body>
</html>

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

0

@diafol,

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.

0

@diafol:

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.