jQuery-Validation-Engine icon indicating copy to clipboard operation
jQuery-Validation-Engine copied to clipboard

How can I use ajax validation to validate a File?

Open nosensezzz opened this issue 12 years ago • 7 comments

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 ...

nosensezzz avatar Mar 25 '14 01:03 nosensezzz

What exactly are you trying to validate?

MB34 avatar Mar 25 '14 16:03 MB34

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'; ...

nosensezzz avatar Mar 25 '14 19:03 nosensezzz

Can you show your ajax rule AND your PHP code?

MB34 avatar Mar 25 '14 20:03 MB34

"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) .

nosensezzz avatar Mar 26 '14 02:03 nosensezzz

Without seeing your user/avatarCheck code, I can't comment further on this issue.

MB34 avatar Mar 26 '14 13:03 MB34

In order to replicate this, can you also post your form code?

MB34 avatar Mar 26 '14 14:03 MB34

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.

nosensezzz avatar Mar 26 '14 21:03 nosensezzz