Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i need to upload/send image and input title (type="hidden" and value="test_title") using jquery upload plugin. now I have this function:

JS:

<script language="javascript" type="text/javascript">
$(function()
{
    var btnUpload=$('#upload');
    var status=$('#status');
    new AjaxUpload(btnUpload, {
    action: 'upload-file.php',
    name: 'uploadfile',
    onSubmit: function(file, ext)
    {
     if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
     // extension is not allowed 
    status.text('Only JPG, PNG or GIF files are allowed');
    return false;
    }status.html('<img src="30.gif">');
    },

    onComplete: function(file, response)
    {
        //On completion clear the status
        status.text('');
        //Add uploaded file to list
        var bb=response.substr(0,7)
        var idd=response.replace('success',' ');
        var idb =idd.replace(/^\s*|\s*$/g,'');
        if(bb==="success")
        {
            $('<span id='+idd+'></span>').appendTo('#files').html('<img src="images/'+file+'" alt="" width="120" height="120" style="margin:5px;" /><br><a href="javascript:void(0)" onClick="deleteFile('+idd+');">Delete</a>').addClass('success');
        }
        else 
        {
            $('<span></span>').appendTo('#files').text(response).addClass('error').hide("slow");

        }
    }});
});

function deleteFile(id)
{   var status=$('#status');
    var aurl="delete-file.php?imageid="+id;
    var result=$.ajax({
        type:"GET",
        data:"stuff=1",
        url:aurl,
        async:false
    }).responseText;
    if(result!="")
    {

        $("#"+id).animate({ backgroundColor: "#fbc7c7" }, "fast")
        .animate({ opacity: "hide" }, "slow");
    }
}
</script>

HTML:

<form method="post" enctype="multipart/form-data">
<tr>
    <td width="25%">Title :</td>
    <td><input type="hidden" name="title" id="title" size="30" value="test_title"/></td>
</tr>

<tr>
    <td valign="top">Item Avatar :</td><td valign="top">
    <div id="upload" ><span>Upload Image<span></div><span id="status"></span>
    <table><tr><td id="files"></td></tr></table>
    </td>
</tr>
<tr>
    <td colspan="2" align="center">
    <input type="submit" name="add_item" value="Submit" id="sub_button" />&nbsp;
    </td>

</tr>
</form>

upload file.php

<?php
session_start();
require_once("config.php");
$limit=3;
$uploaddir = 'images/'; 
$nam=$_FILES['uploadfile']['name'];
$file = $uploaddir . basename($_FILES['uploadfile']['name']); 

    $title=$_POST['title'];

    if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) 
    { 
        $insert=mysql_query("insert into match_item_image set item_id='".$title."', image='".$nam."'") or die(mysql_error());
$cc=mysql_insert_id();
        echo "success".$cc; 
    }
    else 
    {
        echo "error";
    }   
?>

Now, My Form can't Send $_POST['title'] to upload-file.php. how to send title from my form to upload-file.php using jquery upload plugin!?

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.