Getting file while updating entry - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Getting file while updating entry (/showthread.php?tid=27693) |
Getting file while updating entry - El Forum - 02-17-2010 [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"> Thanks. Getting file while updating entry - El Forum - 02-17-2010 [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. Getting file while updating entry - El Forum - 02-17-2010 [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 <input> tag. The <img> tag shows the image correctly. Trying to get something like <input type="file" value="image_path/image.jpg">but it does not work. I think it's because of the browsers security. I think you can't "preselect" or "prefill" the <input> tag of file type. Thanks for such quick reply. Getting file while updating entry - El Forum - 02-17-2010 [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: <input type = 'hidden' value = 'image_path'> 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. Getting file while updating entry - El Forum - 02-18-2010 [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) Thanks for help. Getting file while updating entry - El Forum - 02-18-2010 [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. |