Hi there ,
How to retain value file upload input in codeigniter?
Please give me an idea?

i am using below one: but not working..

<input type="file" name="image1" value="<?php echo set_value('image1')?>" class="form-control" style="width:300px;" id="dealImg">

Recommended Answers

All 5 Replies

Hi,

you cannot do this, the HTML specification does not allow to set a value for the input file type element. Otherwise a website could try to access to any file in the local system of the client.

Here you can see the attributes that you can set:

Here is a good example from ellislab you can start with this one

@philjen

Hi, OP asks if he can use set_value() to return the uploaded file path when going back to the form due, for example, to the validation process.

The function set_value() will not work with an input file type tag because of the HTML specification and because browsers do not allow to preset a value for this type of input field.

In practice:

<input type="file" name="image1" value="/path/to/file.jpg" />

does not work. The value attribute is not accepted.

Alternative: when the form is submitted, if the validation does not fail because of the file but due to another input field, he can save the file and when going back to the form, show the file a part. Like an attachment, with the option to replace it.

Also note that Ellislab does not support anymore CodeIgniter, from now on you should refer to:

I believe that this post is live only because the author didn't marked it as solved , he made a second post in this sequence with another approach , so it isn't really an active thread.

@philjen it is great that you want to help others and I hope you continue doing so here , but take a moment to read their questions.

Is there a way to emulate repopulate of the contents of a file input in modern browsers ? .. Yes , but this is far too complicated for the question. If this is what the author tried to do , and had no alternatives there are ways (it is more a JS matter than PHP) , but the question has many simple solutions that just need an effort to understand how web works in its elementary levels.

cant we save the file in session. and then we can access ?

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.