java脚本函数,我希望它在上传图像并在数据库中完成新值后显示。 整个页面代码是这样的:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<style type="text/css">
body
{
font-family: Helvetica, Arial;
}
.backdrop
{
position:absolute;
top:0px;
left:0px;
width:100%;
height:100%;
background:#000;
opacity: .0;
filter:alpha(opacity=0);
z-index:50;
display:none;
}
.box
{
position:absolute;
top:20%;
left:30%;
width:500px;
height:300px;
background:#ffffff;
z-index:51;
padding:10px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow:0px 0px 5px #444444;
-webkit-box-shadow:0px 0px 5px #444444;
box-shadow:0px 0px 5px #444444;
display:none;
}
.close
{
float:right;
margin-right:6px;
cursor:pointer;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('.lightbox').click(function(){
$('.backdrop, .box').animate({'opacity':'.50'}, 300, 'linear');
$('.box').animate({'opacity':'1.00'}, 300, 'linear');
$('.backdrop, .box').css('display', 'block');
});
$('.close').click(function(){
close_box();
});
$('.backdrop').click(function(){
close_box();
});
});
function close_box()
{
$('.backdrop, .box').animate({'opacity':'0'}, 300, 'linear', function(){
$('.backdrop, .box').css('display', 'none');
});
}
</script>
<!-- <a href="#" class="lightbox">Open Lightbox</a> -->
<div class="backdrop"></div>
<div class="box" style="margin: 0 auto; width:100%; height:400px;">
<div class="close">x</div>
<object type="text/html" data="includes/widgets/demos/tutorial3.php"
style="width:100%; height:100%; margin:1%;">
</object>
</div>
<div class="widget">
<h2>Hello, <?php echo $user_data['first_name'];?>!</h2>
<div class="inner">
<div class="profile">
<?php
if (isset($_FILES['profile']) === true) {
if (empty($_FILES['profile']['name']) === true) {
echo 'Please choose a file';
} else {
$allowed = array('jpg', 'jpeg', 'gif', 'png');
$file_name = $_FILES['profile']['name'];
$file_extn = strtolower(end(explode('.', $file_name)));
$file_temp = $_FILES['profile']['tmp_name'];
// u can put one for file size here
if (in_array($file_extn, $allowed) === true) {
change_profile_image($session_user_id, $file_temp, $file_extn);
//header('Location: ' . $current_file);
exit();
} else {
echo 'Incorrect file type. Allowed: ';
echo implode(', ', $allowed);
}
}
}
if (empty($user_data['profile']) === false){
echo '<img src="', $user_data['profile'], '" alt="', $user_data['first_name'] , '\'s Profile Image">';
}
?>
<iframe id="myIframe" name="myIframe" width="0" height="0" frameborder="0"></iframe>
<form action="" method="post" enctype="multipart/form-data" target="myIframe" >
<input type="file" name="profile"> <input type="submit" class="lightbox">
</form>
</div>
<ul>
<li>
<a href="logout.php">Log out</a>
</li>
<li>
<a href="<?php echo $user_data['username']; ?>">Profile</a>
</li>
<li>
<a href="changepassword.php">Change password</a>
</li>
<li>
<a href="settings.php">Settings</a>
</li>
</ul>
</div>
</div>
java脚本函数:
$(document).ready(function(){
$('.lightbox').click(function(){
$('.backdrop, .box').animate({'opacity':'.50'}, 300, 'linear');
$('.box').animate({'opacity':'1.00'}, 300, 'linear');
$('.backdrop, .box').css('display', 'block');
});
$('.close').click(function(){
close_box();
});
$('.backdrop').click(function(){
close_box();
});
});
在上传代码后显示:
if (in_array($file_extn, $allowed) === true) { change_profile_image($session_user_id, $file_temp, $file_extn);