How can I use ajax validation to validate a File?
if I ajax validate this input, i got
'fieldId' => string 'picture' (length=7) 'fieldValue' => string 'C:\fakepath\1.jpg' (length=17)
this fieldValue is wrong.
How can I get the whole file, like file_name, file_size, tmp, type ...
What exactly are you trying to validate?
I user ajax validation on a file type input, but when I validate this file on back end , which is a PHP file, it didn't receive the whole file but a fake file
For example, there is a picture which I was validating it. But at back end, this fieldValue is 'fieldValue' => string 'C:\fakepath\1.jpg' (length=17)
it suppose to be a FILE, like
$_FILES['tmp_name'] = 'xxx.tmp' $_FILES['name'] = 'xxx.jpg'; $_FILES['size'] = '787878'; ...
Can you show your ajax rule AND your PHP code?
"ajaxAvatarCall": { // remote json service location "url": "/" + site + "/user/avatarCheck",
"extraDataDynamic":['#picture'],
"alertText": "* This Email is already taken",
// speaks by itself
"alertTextLoad": "* Validating, please wait"
},
ajax rules here,
I use another way to do the job, so php code no longer exist, but problem is pretty straight, #picture is a file type input, but you can't get real data of this file, you just got some fake data. like 'fieldValue' => string 'C:\fakepath\1.jpg' (length=17) .
Without seeing your user/avatarCheck code, I can't comment further on this issue.
In order to replicate this, can you also post your form code?
I delete the back side code because I use another method to do it.
But it should not a bug at back end, even I just var_dump($_POST), it will not show any file information.
And I did put enctype="multipart/form-data" at form , so it should be able to send file.
Anyway, thank you for you reply.
Maybe the ajax rule need put a variable like enctype="multipart/form-data" to allowed file type?
If anyone can post a example of how to use this to ajax validate file data will be great.