图片上传,AJAX,PHP和MySQL图片上传、AJAX、MySQL、PHP

由网友(不懂悲痛)分享简介:我有一个问题。从文件输入可以上传图片到MySQL与阿贾克斯POST和PHP?这样的:<脚本类型=文/ JavaScript的>$(文件)。就绪(函数(){$(按钮)。点击(函数(){$(#form_id)。递交(函数(){$阿贾克斯({键入:POST,数据:IMAGE_DATA,网址:/ path_to...

我有一个问题。 从文件输入可以上传图片到MySQL与阿贾克斯POST和PHP?

这样的:

 <脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
    $(按钮)。点击(函数(){
    $(#form_id)。递交(函数(){
            $阿贾克斯({
            键入:POST,
                数据:IMAGE_DATA,
                网址:/ path_to_php / ImageSave.php
                成功:函数(MSG){
                        警报(正常);
                    }
            });
            返回false;
        });
    });
});
< / SCRIPT>
<表格名称=FORM_NAMEID =form_id行动=#的方法=POST>
    <输入类型=文件名称=形象ID =形象/>
    <按钮>保存< /按钮>
< /形式GT;
 

解决方案

上传文件,并将其存储在数据库中可以通过多种方式来实现。 这是一款教程这样做。。但是,如果你想这样做,使用Ajax,这是绝对有可能的问题是,的看看这个但犯规支持几乎常见的浏览器,解决的办法是:

使用的iframe:检查本教程 使用jQuery插件检查这篇文章

I have one question. Is possible upload image from file input to MySQL with Ajax POST and PHP?

PHP 头像上传到mysql数据库

Like this:

<script type="text/javascript">
$(document).ready(function(){
    $("button").click(function(){
    $("#form_id").submit(function(){
            $.ajax({
            type:"POST",
                data:image_data,
                url:"/path_to_php/ImageSave.php",
                success: function(msg){
                        alert("ok");
                    }
            });
            return false;
        });
    });
});
</script>
<form name="form_name" id="form_id" action="#" method="POST">
    <input type="file" name="image" id="image" />
    <button>Save</button>
</form>

解决方案

upload file and store it on database can be done by several ways. this is one tutorial for doing this.. But the problem is if you want to do that using Ajax, it is definitely possible, check this out but almost common browser doesnt support it, the solution is:

using iframe: check this tutorial using jquery plugin check this article
阅读全文

相关推荐

最新文章