用jquery帖子上传php图片 [英] php image upload with jquery post

查看:102
本文介绍了用jquery帖子上传php图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ı想用jquery帖子上传图片。我不想使用表格。

ı want to upload image with jquery post. ı dont want to use form.

问题是ı刚得到图像名称,ı不能用这个:

the problem is ı just got image name, ı cant use this:

 $size=filesize($_FILES['image']['tmp_name']);

 $copied = copy($_FILES['image']['tmp_name'], $newname);

我的jquery函数:

my jquery function:

$('#add').click(function(){

    var image=$('#image').val();


    $.post(
            'select.php?p=up',
            {img:image},
            function(answer){

                $('#sonuc').html(answer);
            }
    );

});

html代码:

<form name="newad" method="post" enctype="multipart/form-data"  action="" id="form">
<table>
<tr><td><input type="file" name="image" id="image"></td></tr>
<tr><td><input name="Submit" type="button" value="Upload" id="add"></td></tr>
</table>    
</form>

不是:当提交表格时它起作用,但它不会像这样工作,并且ı必须这样做。

not: it works when ı submit form but it doesnt work like this, and ı have to do this.

推荐答案

我建议使用jsupload插件来实现此目的。你的javascript将是:

I recommend using jsupload plugin for this purpose. Your javascript would be:

$(document).ready(function() {
$("#uploadbutton").jsupload({ 
    action: "addFile.do",
    onComplete: function(response){
      alert( "server response: " + response);
    }   
});

这篇关于用jquery帖子上传php图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆