What is the best way to upload files with Ajax?

Asked

Viewed 1,104 times

6

I could take a code on the Internet paste here and try an answer but I prefer that help me with the logic and programming of a script to upload images in Ajax. I don’t know how to start, I’m a beginner but I already know a few things about jQuery and Ajax. In this upload I will register 5 fields in the database that are;

id, nome(md5), titulo, descricao, datacadastro
  • 1

    I find it interesting to show a little research effort and at least some implementation attempt. See [Ask]

  • I’ve been struggling to learn, you can see in my other questions. I just didn’t post code this time because there’s so much going on that I didn’t want to get it wrong.

  • 1

    A place to start: http://forum.codecall.net/topic/37937-php-upload-class/

  • 5

    If you’re a beginner, I don’t recommend doing the client-side part from scratch. It has many details needed to work cross-browser (such as fallback using iframes), it is better to use a ready-made library that already solves these things. For example: https://github.com/blueimp/jQuery-File-Upload

  • Search on plupupload is the best plugin I’ve ever found...

  • The jQuery-File-Upload quoted by @bfavaretto is really good! See the amount of Forks from the project on github. I think it is worth seeing it working on the example page (http://blueimp.github.io/jQuery-File-Upload/) and read the documentation on the link already mentioned.

  • 1

    If you don’t feel comfortable with jquery or don’t want to use the http://blueimp.github.io/jQuery-File-Upload/ plugin mentioned earlier, another option would be to set the target of the form to an iframe.

  • To solve my image upload problem, I ended up using jQuery File Upload. Thank you to everyone who commented.

  • The ideal is to look for examples that use php to do the upload process, have classes just for this.

Show 4 more comments

2 answers

6


A tip is that you upload the content separately.

Make a command with the programming language you will use, making an INSERT for the data as name, title, etc.

After you have made the SQL command to insert only the content, make a page or block on the same page with this upload plug-in via jQuery:

http://hayageek.com/docs/jquery-upload-file.php

In this plug-in, it uploads multiples using PHP, jQuery and Mysql, plus it has many options like specifying allowed extensions, 'drag & drop files to upload' option, uploads progress bar, upload response output and etc.

I used this plug-in and did not regret it as it helped my need in 100%.

2

A simple way to do this you find here.

I just add...

The suggested libraries and classes are all valid and will show you "the way," but if you want to try to implement on your own then start by doing without Ajax.

Start with the form, then receive the data (images) by php, resolve the issue of DB and finally implement Ajax.

The link I gave you should help you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.