Sir I have these codes

[PHP] <form name="form1" action="<?php $_PHP_SELF ?>" method="post" enctype="multipart/form-data">

  <p<Photo</p>    
  <p><input type="file"  name="file" id="file" value="<?php echo $myphoto; ?>"></p>
  <p><input type="submit" value="photo" name="save"></p>

</form>[/PHP]

and these are codes for submit button

[PHP]if(isset($_POST['save']))
    {
         if(isset($_FILES["file"])){
            $myphoto=$_FILES["file"]["name"];
            echo $myphoto;
        }else{
             echo 'Error'; 
         }
     }  [/PHP]

When I press save button the it shows the selected name properly,

But it immediately make file input blank like this

Untitled.png

Why php echo is not working in this line?

[PHP] <p><input type="file"  name="file" id="file" value="<?php echo $myphoto; ?>"></p>[/PHP]

File name must remain appear after echo.

Please help

Recommended Answers

All 2 Replies

You're setting the value of myphoto upon submitting the form. Before the form has been submitted, it has no value.

Oh, sorry. I'm on my phone and it was hard to understand your question. That's just how th bro see file uploaded works. It automatically shows the file name of the file browser for on the local system. You can't populate it with your own string.

Perhaps instead just remove the file input form and replace it with "file name successfully uploaded".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.