0

Hello there Good day to each and everyone of us here.
i have a problem displaying the image i have uploaded in the root directory folder. This is my codes in uploading image. I am using jquery.min.js and jquery.form.js.

$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
{
$actual_image_name = time().".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name))
{
mysql_query("UPDATE users SET profile_image='$actual_image_name' WHERE student_id='{$_SESSION['user_id']}'",$link_id);
echo "<img src='uploads/".$actual_image_name."'  class='preview'>";
}
else
echo "failed";
}
else
echo "Image file size max 1 MB"; 
}
else
echo "Invalid file format.."; 
}
else
echo "Please select image..!";
exit;
}
?>

i have tried using this script to display the image uploaded on the other page.

<div id="about-img">
<?php 
$actual_image_name = time().".";
mysql_query("UPDATE users SET profile_image='$actual_image_name' WHERE student_id='{$_SESSION['user_id']}'",$link_id);
echo "<img src='uploads/".$actual_image_name."'  class='profile-photo'>";
?>
</div>

but the image shows empty picture.
Please advise.

4
Contributors
3
Replies
25
Views
2 Years
Discussion Span
Last Post by mattster
0

time() returns the actual time. So the time used in the upload, and the one for the display are different. You need the store the name you use for the upload, so you can use the exact same one when displaying.

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.