0

My HTML is as follows

<form id="df" enctype="multipart/form-data">
<input type="email" name="email">
<input type="file" name="image">
<button type="submit" id="submit">Submit</button>
</form>

My Script

$(document).ready(function()
{
   $("#df").submit(function(event)
    {
      event.preventDefault();
      $.ajax
      ({
        type: 'POST',
        url: 'review.php',
        data: new FormData(this),
        contentType: false,
        cache: false,
        processData:false,
        success: function(data)
        {
            $('#preview').html(data);
        }
     });
    return false;
   });
});

My PHP script

<?php
$file = $_POST["email"];
$path = "uploads/$file";
mkdir($path);

 $t = $path.'/'.$_FILES['image']['name'];
 $s = $_FILES['image']['tmp_name'];
 echo "File name : " .$_FILES['image']['name']. "</br>";
 echo "File type : " .$_FILES['image']['type']. "</br>";
 echo "File size : " .$_FILES['image']['size']. "</br>";

 move_uploaded_file($s,$t);

 if (is_uploaded_file($_FILES['image']['tmp_name'])) {
     echo "File ". $_FILES['image']['name'] ." uploaded successfully.\n";
 }
 else {
 echo "File Not uploaded";
 }

echo '<img src="'.$t.'" alt="No image selected" class="img-responsive">';
?>

I get the following output.

File name : IMG_20150526_194112.jpg
File type : 
File size : 0
File Not uploaded

Subfolder with name email-id is being created in uploads folder, but image in not uploading to that folder. Where is it going wrong?

2
  • maybe the file is not an image Commented Sep 10, 2015 at 10:59
  • Maybe it has to do with permissions. Try chmod ? Commented Sep 10, 2015 at 11:05

1 Answer 1

2

You need to add enctype="multipart/form-data"> in your form tag. It would be

<form id="df" enctype="multipart/form-data">
Sign up to request clarification or add additional context in comments.

1 Comment

My mistake, I haven't put that before. Yes I have enctype.

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.