javascript - Ajax to php retrieving formdata
Get the solution ↓↓↓I'm sending my files through vue.js to my laravel backend but I'm not able to retrieve the data correctly.
Vue.js :
<b-form-file
v-model="files"
:state="Boolean(files)"
placeholder="Choisissez un fichier..."
drop-placeholder="Glisser ici..."
multiple
accept=".jpg, .png"
class="textOverflow"
name="file[]"
></b-form-file>
Ajax :
onSubmit(){
let formData = new FormData();
for( var i = 0; i < this.files.length; i++ ){
let file = this.files[i];
formData.append("filePos: "+ i, file, this.id);
}
axios.post('/pictures', formData,
{headers: {'Content-Type': 'multipart/form-data'} })
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
}
Laravel php :
public function store(Request $request)
{
$images = $request->all();
info($images);
}
So this gives me :
[2020-04-26 15:40:48] local.INFO: array (
'filePos:_0' =>
Illuminate\Http\UploadedFile::__set_state(array(
'test' => false,
'originalName' => '25',
'mimeType' => 'image/png',
'error' => 0,
'hashName' => NULL,
)),
)
[2020-04-26 15:40:50] local.INFO: array (
'filePos:_0' =>
Illuminate\Http\UploadedFile::__set_state(array(
'test' => false,
'originalName' => '25',
'mimeType' => 'image/png',
'error' => 0,
'hashName' => NULL,
)),
)
Which is perfect, but I can't retrieve specific data like if I just want the originalName and do ->request('name'), I can the weird chain of characters as if I wasn't the correct encoding.
Does someone know how to retrieve specific information for separating the images, manipulate them and so.
Thanks for reading
Edit :
If I use dd instead of info :
array:1 [
"filePos:_0" => Illuminate\Http\UploadedFile {#343
-test: false
-originalName: "25"
-mimeType: "image/png"
-error: 0
#hashName: null
path: "C:\Users\Gian\AppData\Local\Temp"
filename: "phpEC28.tmp"
basename: "phpEC28.tmp"
pathname: "C:\Users\Gian\AppData\Local\Temp\phpEC28.tmp"
extension: "tmp"
realPath: "C:\Users\Gian\AppData\Local\Temp\phpEC28.tmp"
aTime: 2020-04-26 16:28:39
mTime: 2020-04-26 16:28:39
cTime: 2020-04-26 16:28:39
inode: 35184372088948345
size: 109758
perms: 0100666
owner: 0
group: 0
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
linkTarget: "C:\Users\Gian\AppData\Local\Temp\phpEC28.tmp"
}
]
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: uncaught error: call to undefined function mysqli_connect()
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.