0

I want when I go to update form to show the image name from database there were is write "No file chosen" or to auto-select the photo from the database. All the data from my database is loaded on the fields. Is that possible?

Photo image to see what i mean:

enter image description here

HTML image form:

<b>Poze</b>
<font color="red">*</font> 
<input type="file" name="image">

PHP code for image:

$folder ="uploads/"; 
$path = $folder . $image ; 
$target_file=$folder.basename($_FILES["image"]["name"]); 
$imageFileType=pathinfo($target_file,PATHINFO_EXTENSION);
$allowed=array('jpeg','png' ,'jpg'); $filename=$_FILES['image']['name']; 
$ext=pathinfo($filename, PATHINFO_EXTENSION); 
if(!in_array($ext,$allowed) ) { 
    $errMsg = 'Se accepta doar imagini. Extensie: JPG, PNG, GIF.';
}
else{ 
    move_uploaded_file( $_FILES['image'] ['tmp_name'], $path);
}
Ivan
  • 11,733
  • 5
  • 35
  • 63
Snuk
  • 33
  • 6
  • It is not possible to set the value of a file picker. You have to fake it using another frontend field (a separate HTML element) that is styled in the way you want and that proxies the click to the file picker so it still works (just behind the scenes). [*"You cannot set the value of a file picker from a script — doing something like the following has no effect:"*](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#File_inputs) – h2ooooooo Jun 25 '18 at 17:02

2 Answers2

0

HTML - Display image after selecting filename

answers the question nicely with a javascript snippet look down at the first answer

Avi Teller
  • 174
  • 1
  • 1
  • 7
0

I found a solution but it involves some java script. I hope this helps.

Try and fiddle with this

HTML

<input type="file" id="browse" name="fileupload" style="display: none" onChange="Handlechange();"/> 

Java Script

    function HandleBrowseClick()
{
    var fileinput = document.getElementById("browse");
    fileinput.click();
}

function Handlechange()
{
    var fileinput = document.getElementById("browse");
    var textinput = document.getElementById("filename");
    textinput.value = fileinput.value;
}

Query the name of the file from the database and then you can create an html tag to display the file name.

Codebender
  • 147
  • 2
  • 10