我是php编程的新手。我正在创建一个用户配置文件,我需要允许用户上传个人资料图片。所以我编码像这样
<?php echo form_open_multipart('','class="form-horizontal span4"');?>
<img src="PATH TO IMAGE" />
<input type="text" name="userfile" />
<input class="btn" type="submit" value="Upload" />
<?php echo form_close();?>
所以我得到了一个像上面那样的结构。
但我需要的是像第二张图片中的那个。这可能......如果是,请帮助或至少分享一个链接。
答案 0 :(得分:1)
基本上,您所做的是将默认上传输入移到页面外部,例如将其绝对左侧设置为-300px。然后你有自己的按钮点击以使用javascript触发真实的按钮。很简单。附:您无法通过可见性或显示来隐藏它:无,因为它不会触发。幸运的是,移开它不会禁用它。
答案 1 :(得分:0)
您无法更改默认值,即Browse
,但可以通过在浏览按钮上重叠图像来使用css实现此目的。
在Css Somethig中(customize it according to your HTML attribute
):
div.fakefile img {
float: left;
margin: 0 0 0 -96px;
}
根据您的评论I want to browse using browse button and when upload is clicked i need to upload
。除此之外:
<input type="submit" value="upload" name="sub"/>
<input type="file" name="img"/>
现在您可以通过按上传按钮提交表单,如果您已为此编码,则会上传图片。使用此function进行上传