我找到了这个代码来上传个人资料图片,
一切都很好。但我想设置一个名称文件 = user_id
我如何将输入隐藏的 user_id 值传递给 php 上传文件过程?
var uploadURL = "processupload.php";
$(document).ready(function(){
$('a#uploadFile').file();
$('a#delete').click(function(){
$('input#profileImageFile').val("");
$('img#profileImage').attr("src","/images/styles/profileBlank.jpg");
$('div#messageBox').html("Image deleted !");
$('div#messageBox').attr("class","success");
$('a#delete').hide();
});
$('input#uploadFile').file().choose(function(e, input) {
input.upload(uploadURL, function(res) {
if (res=="invalid"){
$('div#messageBox').attr("class","error");
$('div#messageBox').html("Invalid extension !");
}else{
$('div#messageBox').attr("class","success");
$('div#messageBox').html("Imagen cargada !");
$('img#profileImage').attr("src","/images/avatars/"+res);
$('input#profileImageFile').val(res);
$('a#delete').show();
$(this).remove();
}
}, '');
});
});
html
<div class="imageContainer">
<img alt="" src="/images/avatars/<?php echo $row_rs_user['user_image']; ?>" width="150" height="150" id="profileImage">
<a href="#" id="uploadFile" title="Upload"><img alt="" src="/images/styles/upload.jpg"></a>
<a href="#" id="delete" title="Delete" style="display:none;position:relative;z-index:999999;"><img alt="" src="/images/styles/delete.jpg"></a>
<input type="hidden" name="user_id" value="<?php echo $row_rs_user['user_id']; ?>">
<div id="messageBox"></div>
</div>
PHP上传过程
if(isset($_POST))
{
.
.
.
.