SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery: Upload image without submitting form?

    I'm trying to upload an image without submitting the form. Here is what I got:
    Code JavaScript:
    jQuery('.uploadbox').change(function() {
        jQuery.ajax({
            type: "POST",
            url: "includes/friserupload.php",
            success: function(){
                jQuery('div.success').fadeIn();
            }
        });
        return false;
    });

    The formobject:
    Code HTML4Strict:
    <input type="file" name="uploadbox" id="uploadbox" class="uploadbox" size="35"">

    And friserupload.php
    PHP Code:
    move_uploaded_file($_FILES["uploadbox"]["tmp_name"],
    "../frisers/" $_FILES["uploadbox"]["name"]); 
    It comes out as executed but no file in the folder? Any ideas?

    Thanks in advance...

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    From what I can tell, $.ajax and its friend $.post aren't really built for making uploading files easily, which seems like a rather odd shortcoming. It seems like you need plugins to make it easier. The thing is that until recently you did need to submit a form to upload files, and therefore a hidden iframe is normally used. I say that because of the relatively new uploading capabilities of the HttpXMLRequest object and its related File API that Firefox and Chrome support.

    In a nutshell, the easiest thing is to use a jQuery plugin like this or this
    I wrote my own script that would also display a thumbnail of the image (via the FileReader object of the File API) and employ drag-and-drop of files directly onto the page, as well as multiple uploads. This helped me quite a bit: Ajax Upload; A file upload script with progress-bar, drag-and-drop.

    I can post the code I wrote if you want.

  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    I can post the code I wrote if you want.
    Thanks Raffles. I will look into it. It would be great with your code for examples...

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Actually, my code is too focused on a particular application to be very useful, so I think you'd be better off looking at the code I said helped me write my own.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •