0

we can set PHP variable as the value of input in HTML form like this

<input type="number" name="price" value="<?php echo $editprice;?>" >

but this doesn't work for input with type file. I try it this way

<?php
$sqlch15="SELECT image1 FROM pc where id=$idtoe";
$resultch15= mysqli_query($db, $sqlch15);
while ($row = mysqli_fetch_array($resultch15))
{
  $editimg1 = "<img src='images/"  .$row['image1']."'>";
} 
?>

<input type="file" name="image1" value = "<?php echo $editimg1;?>">

but it doesn't work what is my mistake help me.

3
  • 2
    It's not a mistake, it's just not allowed by the browser, for security reasons - you can't try to automate the user selecting a specific file, they have to that themselves manually. It's a way of ensuring the user consents to uploading that file. And anyway it makes no sense to specify $editimg1 as the file because that points to a path on the server, not on the user's machine. So even if it was allowed, your idea wouldn't work Commented Jun 4, 2020 at 15:19
  • you can't, because of security reasons Commented Jun 4, 2020 at 15:23
  • what do you want to fill there, the location on the client computer, the upload location, or the raw picture ? Commented Jun 4, 2020 at 15:32

2 Answers 2

1

The value property contains the complete path of the file. The value property of the input:file element is read-only, because of security reasons.

Sign up to request clarification or add additional context in comments.

Comments

0

if you press that button you upload a picture into the /tmp folder of the server (or another folder designed for that)

You will create a Array variable called $_FILES['image']

[_FILES] => Array
    (
        [image1] => Array
            (
                [name] => example.png
                [type] => image/png
                [tmp_name] => /tmp/phpq0JHjV  // that is the upload folder
                [error] => 0
                [size] => 10847
            )
    )

So the only thing that would make a little sense is to fill in the name of the file

<input type="file" name="image1" value="<?=$_FILES['image']['name'];?>">

But as I said it makes no much sense because the info about the path to this file on the client is missing.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.