Welcome Guest, Not a member yet? Register   Sign In
Getting file while updating entry
#1

[eluser]babalooi[/eluser]
Hi, everybody.
I'm having trouble while trying to update entry from database.
Every field in form gets repopulated with data, except
Code:
<input type="file">
Is there any way to get image that is already uploaded back in form , so I don't have to browse for it again?

Thanks.
#2

[eluser]ciGR[/eluser]
If I understand well what tou mean, you may use the image tag to show the image, and after the image you can add an <input type=file> and when the user post the form you check if the user has upload an image, if yes you update the entry to the database.
#3

[eluser]babalooi[/eluser]
Yes, I did just that. Image tag and input tag in form, and image shows nicely inside form after creating new entry with new image. But when trying to update it with new data, except image, the form is repopulated with everyrhing but the image file inside &lt;input&gt; tag. The <img> tag shows the image correctly.
Trying to get something like &lt;input type="file" value="image_path/image.jpg"&gt;but it does not work. I think it's because of the browsers security. I think you can't "preselect" or "prefill" the &lt;input&gt; tag of file type.

Thanks for such quick reply.
#4

[eluser]ciGR[/eluser]
You can see when you upload an image in input the path is a local path of the user's computer, so if you can do this an add the path of the image on server, when the user post the form and don't change the image it's browser try to find the path in user's computer to upload the image, but the path you set was on your web server.

But, you can do that you want by add a hidden input and give it for value the image path
like
Code:
&lt;input type = 'hidden' value = 'image_path'&gt;
and when the user post you can get the image path from this input.

But I think there is no need to do that, because if the user dont upload a new image, you have already saved the image path in the database.
#5

[eluser]babalooi[/eluser]
It works. The solution is very simple. I have never used $_FILES before.
Code:
if(isset($_FILES['image']) AND strlen($_FILES['image']['name'])>0)
{
    //upload image
}

Thanks for help.
#6

[eluser]ciGR[/eluser]
Also you can check the $_FILES['image']['error'], so if this is 0 all is ok, and the user has successful upload an image.




Theme © iAndrew 2016 - Forum software by © MyBB