0

我正在尝试将一些信息插入数据库,我的第一页是这样的:

$(document).ready(function() {

    //alert('I am ready to use uploadify!');
    $("#file_upload").uploadify({
        'uploader': 'uploadifyit/uploadify.swf',
        'script': 'uploadifyit/uploadify.php',
        'cancelImg': 'uploadifyit/cancel.png',
        'folder': 'images',
        'auto': false, // use for auto upload
        'multi': true,
        'queueSizeLimit': 4,
        'onQueueFull': function(event, queueSizeLimit) {
            alert("Please don't put anymore files in me! You can upload " + queueSizeLimit + " files at once");
            return false;
        },
        'onComplete': function(event, ID, fileObj, response, data) {
            // you can use here jQuery AJAX method to send info at server-side.
            $.post("insert.php", { name: fileObj.name }, function(info) {
                alert(info); // alert UPLOADED FILE NAME
            });
        }
    });



});

</script>
</head>

<body>
<?php
$img_id=$_REQUEST['img_id'];
?>
<form id="form1" name="form1" action="">
<input type="file" name="file_upload" id="file_upload" /><br />
<input type="hidden" value="<? echo $img_id ;?>" name="image_id"  />

<a href="javascript:$('#file_upload').uploadifyUpload();">Upload File</a>
</form>

而处理形式是:

if(isset($_POST)) {

        //echo $_POST['name'];
        $fileName = $_POST['name'];
        $id = $_REQUEST['image_id'];


        mysql_query("INSERT INTO tbl_images(img_file,img_gal_id) VALUES('$fileName','$id')");
        $inserted_id = mysql_insert_id($dbc);

        if($inserted_id > 0) { // if success
            echo "uploaded file: " . $fileName;
        }

    }

我可以发布 $fileName 但不能发布 $id。

4

2 回答 2

1

在您的处理表单中使用POST而不是REQUEST,并按照软/MMK 推荐的方式使用 JSON 传递image_id值。您可以保存隐藏字段和变量声明并将值注入$.post

$.post("insert.php", 
  { 
    name: fileObj.name, 
    // Add the image_id value to post to insert.php
    image_id: <?php echo $_REQUEST['img_id']; ?> 
  ...

然后在处理中:

$fileName = $_POST['name'];
// Grab the posted value.
$id = $_POST['image_id'];
于 2012-08-20T14:10:01.413 回答
0

试试这样

'onComplete': function(event, ID, fileObj, response, data) {
        // you can use here jQuery AJAX method to send info at server-side.
        $.post("insert.php", { name: fileObj.name,image_id:ID}, function(info) {
            alert(info); // alert UPLOADED FILE NAME
        });
    }
于 2012-08-20T13:50:06.370 回答