【问题标题】:unable to upload images in the folder while using ajax使用ajax时无法上传文件夹中的图像
【发布时间】:2014-10-13 09:26:42
【问题描述】:

我应该使用 Ctrl 键 来上传图片,而我正在使用 Ajax,但问题是,在成功上传数据库中的图片名称时,我无法将它们上传到images

下的文件夹

我有以下代码,它能够在数据库中使用 ajax 上传我的图片,但 无法在文件夹中上传图片

<script>
    function showChar(e){
        if(e.ctrlKey && e.charCode == 98){
            e.preventDefault();

            var j = $('#fl').click();
            if(j){saveImage();}

        }
    }

    function saveImage(){

        //var abc = $('#form1').serialize();
        //alert(abc);return false;

        var fl = $('#fl').val();                        
        if(fl != ''){
            alert('t');
            $.ajax({
                type: 'post',
                url: 'sent.php',
                data: 'fl='+fl,
                success:function(msg){

                }
            }); 

            //$.ajaxFileUpload();           

        }
    }   

</script>
</head>
<body onkeypress="showChar(event);">

<form enctype="multipart/form-data" method="post" id="form1">
    <input type="file" name="fl" id="fl" value=""/>
    <input type="button" name="submit" id="submit" value="Submit" onclick="saveImage();"/>
</form>

查询为

$fl = $_REQUEST['fl'];
    $name = $_FILES['fl']['name'];
    $temp = $_FILES['fl']['tmp_name'];


    move_uploaded_file($temp, 'images/'.$fl);

    $query = "INSERT INTO tbl_browse (fld_name) VALUES ('$fl')";    
    $res = mysql_query($query);

    if(mysql_num_rows($res)>0){ return 'U'; }

【问题讨论】:

    标签: ajax image file-upload ctrl


    【解决方案1】:

    试试这个方法

    https://stackoverflow.com/a/24839628/1640577 检查问题和答案

               $.ajax({
                    type: 'post',
                    url: 'sent.php',
                    data: 'fl='+fl,
                    processData: false,
                    contentType: false , 
                    success:function(msg){
    
                    }
                }); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-05
      • 1970-01-01
      • 1970-01-01
      • 2018-05-28
      • 1970-01-01
      • 1970-01-01
      • 2017-02-10
      • 1970-01-01
      相关资源
      最近更新 更多