Skip to content
Advertisement

problem getting file url using php within img tag

I build a form to upload a image file in a folder using php. The uploading works and I can see the uploaded in file in my directory but when I try to retrive the same image url to display in a certain location, its not working. Here is my code

Im not uploading the whole upload.php file.

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],  $newfilename)) 
  {
        echo $newfilename;
        header("location: welcome.php");
        die();
    
  } 

image location is welcome.php file

<div style="width: 140px; height: 150px; border-radius: 5px; background: #eee;">
         <? php echo $newfilename>
        <img src="<?php $newfilename>" width="140px" height="150px" alt="Upload photo" border-radius="10px"> 
    </div>

Also when I tried to echo $newfilename its showing diffrent value in upload.php file and welcome.php. Actually The file extension is missing, why so diffrence. The correct code to get the uploaded file url

Thanks in advance.

Advertisement

Answer

use

src="<?php echo $newfilename; ?>"

echo value in src tag

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement