2

my HTML here

<body>
<form id="myform" method="POST" action="formprocessing.php" enctype="multipart/form-data">

<input type="text" name="first_name" id="first_name" value=""><b/>
 <input type="text" name="last_name" id="last_name" value=""><br />
 Profile Image: <input name="image"  id="image" type="file" /><br />
 <input type="submit" name="formsubmit" id="formsubmit" onclick="return false" value="Submit">

</form>
<div id="result"></div>
</body>

****my jquery code bellow here****

$(document).ready(function(){

    $('#formsubmit').click(function(){
        var name = $('#first_name').val();
        var lastname = $('#last_name').val();
        var files = $('#image')[0].files[0];

    if (name != '' && lastname != '' && filen != '' ) {
    $.post("formprocessing.php" , {ufname:name,ufiles:filen},
        function(result){
                //$("#spans").html("Email are already exist."); 
                    $('#result').html(result);  
                $('#myform')[0].reset();
                }); 

            }

        });
    });
});         

and my php page where i want to display out is bellow

$name = $_POST['ufname'];
$lastname = $_POST['ulname'];
$img= $_FILES['ufiles']['name'];
echo $name;
echo $lastname;
echo $img;

i just want to submit images and other form element just using jquery and php ,my above code worked but the image file was not upload, how can i do that?

Shahsays
  • 421
  • 1
  • 7
  • 25
shan
  • 79
  • 1
  • 7
  • 1
    _$.post_ IS Ajax. Possible duplicate with this question: http://stackoverflow.com/questions/21164365/how-to-send-image-to-php-file-using-ajax – ADreNaLiNe-DJ Jan 28 '16 at 11:09

1 Answers1

0

if you want to upload image via PHP here is how you can do it

       $extension = pathinfo($_FILES['ufiles']['name'], PATHINFO_EXTENSION);
            $filename = '123_'.uniqid().'.'.$extension;
            move_uploaded_file($_FILES['profile_image']['tmp_name'], '../path/'.$filename);
Shahsays
  • 421
  • 1
  • 7
  • 25