Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6769547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:12:23+00:00 2026-05-26T15:12:23+00:00

I haven’t used much javascript before, and I’m not much of a php programmer

  • 0

I haven’t used much javascript before, and I’m not much of a php programmer either, come to think of it, but I’m attempting to learn by building a little website.

I’ve got a form which has a file upload input which I’m attempting to make all nice sexy with this great script but there doesn’t appear to be a tutorial and the code isn’t commented.

(I think) I know how to make it work ok but I’m interested in how it works. Does anyone fancy taking a quick look at it and telling me what all the code in the js and php file is doing?

I’d really appreciate it 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:12:24+00:00Added an answer on May 26, 2026 at 3:12 pm

    I wouldn’t recommend using this library, first of all, since there are much better ones out there, but your question was how this one worked, not whether it was a good one or not.

    Here goes:

    1. ajaxUpload is called by one of the buttons in the upload form.
    2. ajaxUpload first ensures that all the function arguments are correct, creating an alert box (!) if there’s a problem with one of them. (It would be a better idea to throw an error using throw "error message" instead.)
    3. ajaxUpload then creates an iframe using document.createElement, and gives it zero width and height so it’ll be invisible, before adding it to the document. It gives the iframe the name ajax-temp.
    4. ajaxUpload adds the doUpload function as a onload listener on the iframe. It uses the addEvent function as a cross-browser way to do this.
    5. Next, ajaxUpload sets the calling form’s target attribute to point to the iframe, using the name that it gave the iframe earlier. This causes the form to submit into the iframe, instead of replacing the current page. The function also sets some other attributes on the form, even though it would probably be a better idea to add those attributes in the HTML source and not from Javascript.
    6. Finally, ajaxUpload submits the form using form.submit().
    7. The browser submits the form to the server, causing ajaxupload.php to run.
    8. In ajaxupload.php, the script first checks that the browser did actually send a file (in case a curious user visited the url manually instead of submitting the form), then calls the uploadImage function with a bunch of parameters that it got from the $_REQUEST object.
    9. uploadImage does a bunch of checks on the arguments it receives from the client, making sure that the file isn’t too big, has the right extension, etc. If all the checks are passed, it saves the image and returns the filename where the image was saved. Otherwise it returns the list of errors.
    10. If the result returned by uploadImage isn’t an array of errors, the script returns a success message and an <img> tag with it’s src set to the url of the image. Otherwise, it returns a failure message.
    11. On the client, the return of the success or error message causes the load event on the iframe to fire. The doUpload function, which is registered as a listener, is called.
    12. doUpload removes itself as a listener from the iframe, and runs some javascript code in the context of the iframe by setting the iframe’s src attribute. This code copies the iframe’s contents to the parent page.
    13. Finally, doUpload removes the iframe from the document, waiting a short time beforehand in some browsers.

    Whew, that sure took a while to write.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I haven't used the Zend Router much yet so not sure how difficult or
haven't used regex replaces much and am not sure if how I have done
Haven't done as much of Javascript as I should have done. I am trying
I haven't been able to find much about this but am I the only
I haven't used WPF that much so the solution to this is probably pretty
Haven't really create my own function before, so what I am attempting is to
I haven't found any documentation on this or seen this done before, but is
I haven't used SQLite before and I am looking if I could use it.
Haven't fired up reflector to look at the difference but would one expect to
Haven't seen anything about it here but it seems to solve one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.