Thursday, January 15, 2009

Ajax file upload

Browsers force us to use file inputs for uploads, which are impossible to style. Moreover, form-based uploads look obsolete in modern ajax applications. We can use flash to solve this problem, but javascript works nice too.

View an usage examples for jquery and prototype with various options.

Download

http://valums.com/ajax-upload/

2 comments:

  1. I have been trying to use this with PHP but haven't been able to find a workin example.. can you post the upload.php file along with this thanks
    Sidd

    ReplyDelete
  2. Source: http://valums.com/ajax-upload/

    PHP example:
    $uploaddir = '/var/www/uploads/';
    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "success";
    } else {
    // WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
    // Otherwise onSubmit event will not be fired
    echo "error";
    }

    ReplyDelete