5

I am writing the code for editing a form that contains an input file field. I am getting all the values pulled from database for different field types but the file type input does not show its value.

I have a code that looks like this:

<input class="picturebox" id="logo" name="userfile"  value="<?php echo $discount_details->picture_name;?>" />

But actually in rendered view value attribute is null for userfile field.

How do I load the value of input type when someone is editing the form and does not want to alter the picture entered earlier by him upon edit.

3
  • Do you get any errors or any indication that $discount_details->picture_name actually contains a value? Right after you pull it from the database, dump the value and see that you get. var_dump($discount_details->picture_name) Commented Nov 1, 2013 at 5:12
  • Display his previous image with file field on html form.and check for empty file field and if not empty replace the file with new one. Commented Nov 1, 2013 at 5:13
  • @Hammad sir i want to ask how did you you echo the value of that input text without using session please answer Commented Sep 3, 2014 at 7:22

3 Answers 3

4

you can't give the value attribute to input file type

if you want to show the file content while updating form you can show it in separate tag

like:

<input type="file" /> <span><?php echo $row[column_name]?></span>

here you should consider one thing

if the use is selected new file to upload you can update the column else the use not selected any thing just updated other content without file you should update the column name with old file name.

$file = $_FILES['file']['name'];
                
                
if($file!="") {

move_uploaded_file($_FILES['file']['tmp_name'],'/image/'.$file);
                
} else {

$file = $oldfile;

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

Comments

2

You can just make value field empty and show your old image at just up of that input field(or below).then check after submitting form, if $_POST['userfile'] is empty don't update table.picture_name.

Comments

0

The simple trick is that ; give an id to the tag

    <input type="file" name="file" /> <span name="old" value="<?=$row[column_name]?>"><?php echo $row[column_name]?></span>

Then in PHP make it like this:

    $oldfile = $_POST['old'];
    $file = $_FILES['file']['name'];
    if($file!="") {
      move_uploaded_file($_FILES['file']['tmp_name'],'/image/'.$file);
    } else {
    $file = $oldfile;
    }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.