0
<form method="POST" @submit.prevent="share" >
            <div id="imgs">
            
            Select Images: <input type="file" ref="file" name="file[]" multiple ></form>

      share(){
        var formData=new FormData();
         
  for( var i = 0; i < this.$refs.file.files.length; i++ ){
        let file = this.$refs.file.files[i];
        formData.append('file[' + i + ']', file);
    };

    
        axios.post('http://localhost/11/upload_img.php',formData,{
            headers:{'Content-Type':'multipart/form-data'}
        }).then((res)=>{
            console.log("sent");
            
        });
    }}}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.4/vue.js"></script>
<form method="POST" @submit.prevent="share" >
                <div id="imgs">
                
                Select Images: <input type="file" ref="file" name="file[]" multiple >
        
        
        
  

i send files in vue js like above and here is my PHP codes$filename=$_FILES['file']['name'];

$files=$_FILES['file'];

echo($files);

and i get this error

Notice: Undefined index: file in C:\xampp\htdocs\11\upload_img.php on line 6

1 Answer 1

1

It seems like you did not set "multipart/form-data" for your form enctype attribute, so you wont get $_FILES['file'] in backend side

check What does enctype='multipart/form-data' mean?

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

2 Comments

now i did but still same error , do i need to change anything?
what is the result of var_dump($_FILES) ?

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.