图片上传,AJAX,PHP和MySQL [英] Image upload, ajax, php, mysql

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

问题描述

我有一个问题。 从文件输入可以上传图片到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,这是绝对有可能的问题是,的看看这个但犯规支持几乎常见的浏览器,解决的办法是:

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

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:

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

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