0

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

2
Contributors
2
Replies
20
Views
8 Months
Discussion Span
Last Post by Dani
0

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

Edited by Dani: Phone autocorrect

1

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

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.