You're using the wrong path to show the image. You're using the orginal name of the image $_FILES["image"]["name"]
that was uploaded and then you use the move_uploaded_file
function to move and save the file as $_SESSION['str'].'_5'.$_SESSION['img']
so that doesn't match (can't see how your session variables are created).
Also, is the location where you save the uploaded file to accessable by the client side? Move the file in the public
area of your web application.
Update
I now understand from your comment that you want to save the file in a private location and then show that file in a <img>
element in some HTML template.
I changed the example code to embed the uploaded image into the HTML with base64
.
You can use this function for creating the embed code. I took it from the answer from this question How to embed images...
function dataUri($file, $mime)
{
$contents = file_get_contents($file);
$base64 = base64_encode($contents);
return 'data:' . $mime . ';base64,' . $base64;
}
So then you can use it like:
session_start();
// absolute path including the path to the public folder
$image_dest_path = './public/img/' . $_SESSION['str'] . '_5' . $_SESSION['img'];
// move file to server location
move_uploaded_file($_FILES['image']['tmp_name'], $image_dest_path);
// imbed the image into the HTML.
echo '<img src= "' . dataUri($image_dest_path, 'image/jpg') . '"/>';