0

I am using the file field in webform, I would like to check if the file was successfully uploaded. I was using

.onChange

But that only means that a file was attempted to be uploaded. How can I be sure if the file was correctly uploaded. Would like to do this via javascript/jquery to trigger some next steps.

Thanks.

1

I wouldn't recommend doing this with javascript, you should use a PHP function to inform the client-side of success.

However, if you insist on doing it, you could (in theory) just create a new AJAX call to the location wehre you expect the new file to be. If it errors, it means it wasn't uploaded.

$.ajax({
    url:'http://www.example.com/yourfile.jpg'
    error: function()
    {
        //file not there.
    },
    success: function()
    {
        //file is there
    }
});
6
  • I have to do this without page reload, hence the javascript route. Thanks – pal4life Apr 27 '15 at 14:52
  • His solution is a Javascript solution without a page reload ... it makes use of PHP to check the status of the file on the server. – tenken Apr 27 '15 at 16:09
  • @tenken I was responding to his question about why I cannot use Php. – pal4life Apr 27 '15 at 16:32
  • Ok. Well I dont what to say. Its AJAX. AJAX can use php and appear to be solely JavaScript to the enduser or browser. Go learn JavaScript and callbacks, what you're saying is not making sense. – tenken Apr 27 '15 at 16:44
  • @tenken that javascript doesn't require any PHP... it's just sending an AJAX request to a file. if the file isn't there, it will trigger the error (404), otherwise it will be a "success" because we don't require any other information/response. – user5482 Apr 27 '15 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.