Populate form text field with address to uploaded file
I have a PHP file containing a form with a few text fields (Title, description etc.)
One of the fields is Image, where I want the user to either type the address to an image (http://www.domain.com/image.jpg) or upload one. If the user uploads an image, I store it on my server and want to populate the text field in the form with the address to the file on my server (http://www.mydomain.com/images/image.jpg)
I have tried to solve it by adding an upload button next to the Image text field, which opens a jQuery UI dialog that contains a form with a File field and a Submit button.
It works fine, uploads the image and adds a record in a database table, but I don't know how to populate the Image text field in the first form with the address of开发者_运维技巧 the uploaded file.
Can I do it with PHP, should I use jQuery or should I do it in a totally different way ?
Html input
type image
do not have a text
or value
property to set. It has a src
property which is the image url which it renders. In your case instead of using image input element you can show a span
with the updloaded image url as inner text or html once the upload is complete.
Check out move_uploaded_file, put the file wherever and just put the value where you need it. You can use jQuery to change the value of the text field like $('#myfield').val('new_value');
.
精彩评论