1

I want to get the temp name of image upload using php and ajax.I got the file name of upolad image. But dont get the temp name of image upload.My code is given below.Any body

main.php

    <form action=" " method="POST" enctype="multipart/form-data">
     <div class="form-group">
    <label for="exampleInputFile">File Upload</label>
    <input type="file" name="file" id="file" size="150">
    <p class="help-block">Only Excel/CSV File Import.</p>
    </div>
    <button type="button" class="btn btn-default"
     name="Import" value="Import" onclick="file_up()">
    Upload</button>
    </form>
   <div id="upload_show" >   </div>

     <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

   <script type="text/javascript">
   function file_up()
      {
      var file=$('#file').val();
      $.ajax({
     type: "POST",
    url: 'first_ajax.php',
    data:'file='+file,
    success: function(msg)
     { 
      $("#upload_show").html(msg);
     }
   });
  }
 </script>

first_ajax.php

<?php
    echo $file1 = $_POST['file'];   // for get file name
    echo $file1 = $_POST['file']['tmp_name']; //for get temp name
?>

Can you please give me a suggestion on how to get $_FILES['file']['tmp_name']?

3
  • i need the value $_FILES["file"]["tmp_name"] in ajax page .Now i got the file name.but not temp name in ajax page Commented Dec 10, 2014 at 6:48
  • I dont give form,i used onclick event not submit Commented Dec 10, 2014 at 6:49
  • I have posted a full tutorial for image upload it may help you stackoverflow.com/questions/26861807/… Commented Dec 10, 2014 at 7:21

2 Answers 2

0

For Ajax based file upload i used the http://jquery.malsup.com/form/. Even more functionality like upload progress etc.

Take a look on DEMO Page

Sign up to request clarification or add additional context in comments.

Comments

0
<form action=" " method="POST" enctype="multipart/form-data">
    <div class="form-group">
        <label for="exampleInputFile">File Upload</label>
        <input type="file" name="file" id="file" size="150">
        <p class="help-block">Only Excel/CSV File Import.</p>
    </div>
    <button type="button" class="btn btn-default"
            name="Import" value="Import" onclick="file_up()">
        Upload</button>
</form>
<div id="upload_show"></div>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
   function file_up() {
 var formData = new FormData($('#form')[0]);
                    $.ajax({
                        url: 'first_ajax.php',
                        type: 'POST',
                        data: formData,
                        async: false,
                        success: function(data) {
                            $("#upload_show").html(msg);
                        },
                        cache: false,
                        contentType: false,
                        processData: false
                    });
                }
</script>

Use $_FILES to get file properties. For example:

$file_temp_name = $_FILES['file']['tmp_name'];

Bcause $_POST does not hold any file information you have posted.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.