Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用jquery上载文件而不刷新页面_Php_Jquery_Html_File Upload - Fatal编程技术网

Php 使用jquery上载文件而不刷新页面

Php 使用jquery上载文件而不刷新页面,php,jquery,html,file-upload,Php,Jquery,Html,File Upload,我有一个更新配置文件页面。 它有三个表单,它使用get请求来显示任何一个表单。 像update\u profile.php?type=profile允许用户编辑他的个人资料一样,update\u profile.php?type=settings允许用户编辑他的帐户设置 类型:配置文件有一个文件输入,我希望用户能够上传没有页面刷新。 现在这不能用ajax来完成,所以我需要一个解决方法。我尝试过有人在stackoverflow上发布的iframe方法、xhr2方法和html5+ajax方法 因此,

我有一个更新配置文件页面。 它有三个表单,它使用get请求来显示任何一个表单。 像
update\u profile.php?type=profile
允许用户编辑他的个人资料一样,
update\u profile.php?type=settings
允许用户编辑他的帐户设置

类型:配置文件有一个文件输入,我希望用户能够上传没有页面刷新。 现在这不能用ajax来完成,所以我需要一个解决方法。我尝试过有人在stackoverflow上发布的iframe方法、xhr2方法和html5+ajax方法

因此,如果有人愿意详细地向我解释,我将不胜感激。 这是我的html:

<script type='text/javascript'>    
function nouser() {
        $().toastmessage('showToast', {
            text     : 'The user does not exist',
            sticky   : true,
            position : 'middle-center',
            type     : 'error',
            closeText: '',
            close    : function () {
                console.log("toast is closed ...");
            }
        });

    }
</script>    

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Update Profile</title>
<link rel="shortcut icon" type="image/png" href="includes/template/images/favicon.png" />

<link rel="stylesheet" type="text/css" href="includes/template/css2/style.css" />
<link rel="stylesheet" type="text/css" href="includes/jquery/toast/resources/css/jquery.toastmessage.css" />
<link rel="stylesheet" type="text/css" href="includes/jquery/notification/css/jquery_notification.css" />


<script type="text/javascript" src="includes/jquery/jquery_v_1.4.js"></script>

<script type="text/javascript" src="includes/jquery/toast/javascript/jquery.toastmessage.js"></script>
<script type="text/javascript" src="includes/jquery/notification/js/jquery_notification_v.1.js"></script>
<script type="text/javascript" src="includes/jquery/auto_resize/resize.js"></script>
<script type="text/javascript" src="includes/jquery/jquery_form.js"></script>
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="css2/ie.css" />
<![endif]-->
</head>
<body>
<div class="topBar" >
<marquee>Welcome to The Marshall Meme. Your IP Adress is 127.0.0.1 You are logged in as marshall</marquee>
</div>
<br />
<div class="logo" >

<a href="http://www.themarshallmeme.com"><img src="includes/template/images/logo.png"/></a><br/>
</div>
<center>
<div id="wrap">
<br>
<div class="wrapbg">
<span class="corners-top"><span></span></span>
<a class='nav' href='index.php'>Home</a>
<a class='nav' href='whoson.php'>Whos online</a>
<a class='nav' href='logout.php'>Logout</a> <a class='nav' href='forum.php'>Forum</a>
<span class="corners-bottom"><span></span></span>

</div><div class="wrapbg">
<span class="corners-top"><span></span></span>
<div id="content">
Web name
<hr class="hr1" />
<br />
<ul>
<a href='whats_new.php'><button class='action greenbtn'><span class='label'>Whats new?</span></button></a><a href='friend_requests.php'><button class='action redbtn'><span class='label'>Friend requests</span></button></a><a href='update_profile.php?type=profile'><button class='action greenbtn'><span class='label'>Edit profile</span></button></a><a href='update_profile.php?type=settings'><button class='action bluebtn'><span class='label'>Security Settings</span></button></a><a href='update_profile.php?type=changepass'><button class='action greenbtn'><span class='label'>Change password</span></button></a></div>
<span class="corners-bottom"><span></span></span>
</div><div id='emptydiv'> </div>

 <div class="wrapbg">

<span class="corners-top"><span></span></span>
<div id="content"><br/>
Update profile
<hr class='hr1'>
<form action='' method="POST" enctype="multipart/form-data">
<table>


Profile picture<br>
<img src="uploads/profile_pics/TIFF_06_liam-neeson_01.jpg"></img> 
Thumbnail
<img src="uploads/profile_pics_small/TIFF_06_liam-neeson_01.jpg" ?></img>
<tr><td class="lTxt">Change profile picture:</td> <td><input type="file" name="pic"/></td></tr>   
<tr><td class="lTxt">About me:</td> <td><textarea name='about'>Updating my profile :|
fuck yeaaaa</textarea></td></tr>

<tr><td class="lTxt">Interests:</td> <td><textarea name='interests'>I love web development with jquery and php.
Really awesome! yea</textarea></td></tr>
<input type='hidden' name='action' value='profile'/>
<tr><td></td><td><button id="update_profile" name='update' class="action greenbtn"><span class="label">Update profile</span></button></td></tr>
</table>
</form>  
</a></div>
<span class="corners-bottom"><span></span></span>
</div>     <script type='text/javascript'>    

$(function(){
    $('form[name=update_stuff]').on("submit", function(e){
        e.preventDefault();

        $.ajax({
            url: 'process.php',
            type: 'POST',
            data: $(this).serialize(),
            success: function(data){
                $('#emptydiv').html(data);
            }
        });

    });
});


    </script>
</div>
</br>
<div id="footer">

Copyright &copy; 2010-2011, <a href="http://www.themarshallmeme.com">Marshall Meme</a>. All rights reserved.<br>

There are no users online</div>
</div>
</center>
</body>
</html>
我使用php中的$_文件获取文件名并验证其扩展名和服务器端的大小,因此我需要其中的信息。如何做到这一点?
此外,我是否需要更改表单名称以更新配置文件,并为其编写与同一页面中的其他表单不同的代码?

您必须使用任何服务器脚本上载文件,因此您必须使用Ajax方法,使用Ajax查询,您也可以尝试上传修改


后台上传程序使用flash小程序或隐藏的iframe从页面前景隐藏上传内容。你不能使用ajax自己上传,因为ajax不支持文件,只支持标准格式的数据/字符串。这就是为什么我问我如何使用iframes来上传,我只想知道详细的步骤,因为我尝试了很多教程,还有irc(他们建议我使用插件)。我最后的办法是stackoverflow,我想自己写这篇文章,还有什么我可以做的吗?我不使用插件的另一个原因是,大多数插件只是用于文件上传,我不知道如何配置它们来处理文本输入。知道我的意思吗?在学习uploadify之后,它使用了一个php脚本和$u文件来上传,这很好:D但是它有swf文件,这些文件是用来做什么的?是上传机吗?太糟糕了,我讨厌闪光灯。我不想在我的网站上使用它,只要它有很多漏洞和东西。我还使用php脚本将上传的文件移动到一个文件夹中,我不希望uploadify自己做这件事。你能帮我相应地配置它吗?
$(function(){
    $('form[name=update_stuff]').on("submit", function(e){
        e.preventDefault();

        $.ajax({
            url: 'process.php',
            type: 'POST',
            data: $(this).serialize(),
            success: function(data){
                $('#emptydiv').html(data);
            }
        });

    });
});