>All Tutorials 
Ajax and .NET Ajax and .NET RSS XML
Ajax and ColdFusion Ajax and ColdFusion RSS XML
Ajax and Java Ajax and Java RSS XML
Ajax and PHP Ajax and PHP RSS XML
Ajax and SOA Ajax and SOA RSS XML
Ajax Goodies Ajax Goodies RSS XML
Ajax Tool Ajax Tool RSS XML
Facebook MockAjax Facebook MockAjax RSS XML
Google Web Toolkit Google Web Toolkit RSS XML
JavaScript Framework JavaScript Framework RSS XML
Ruby on Rails Ruby on Rails RSS XML
Technique Introduction Technique Introduction RSS XML
Without XMLHttpRequest Without XMLHttpRequest RSS XML
Yahoo! UI Yahoo! UI RSS XML

PHP AJAX example: asynchronous file upload - file php upload filename form uploaded uploaddir echo

 
Registered tutorials: 501
Registered Users: 24391



Rating: 4.5 out of 10 votes cast


  
Category: Ajax and PHP

PHP AJAX example: asynchronous file upload

Digg this   Post to del.icio.us

Abstract: This article contains example application (trivial file-sharing service, like rapidshare, megaupload or yousendit) which uses IFRAME to upload file. While file is uploaded to hidden frame, user can still access web-page and fill "file description" field

Asynchronous file uploads is quote popular feature in modern AJAX web-applications. However standard AJAX classes (XmlHttpRequest) does not have capabilities to process or send files selected with "file dialog" (input type="file"). This article contains example application (trivial file-sharing service, like rapidshare, megaupload or yousendit) which uses embedded frames (IFRAME) to upload file. While file is uploaded to hidden frame, user can still access web-page and fill "file description" field.
  • Adequate versions of Opera, Firefox, Internet Explorer
  • PHP 4.3.0 or higher
  • PHP 5

How IFRAME file uploading works?

  • There is a simple <form... which contains only <input type="file" ... > field. Target for this form is a hidden IFRAME (with "display: none;" CSS style) and OnChange event for the file field is set to JavaScript function which checks file extension (optional for this example, but very useful in general) and submits form.
  • Special part of the script (marked FILEFRAME, see comments) saves file upload, checks for uploading errors and outputs JavaScript code to that hidden IFRAME. The javascript code uses parent.window.document object, which allows to modify parent document (visible page, which users is viewing). It sets filename value and enables submit button on the other form using getElementById method.
  • The other form has 'description' text-field and hidden field 'filename'. User may fill 'description' field while file is uploading. When file uploading is finished, user press submit and "file information" page is generated (based on filename from hidden field and user's file description).

Read Full Tutorial...



Reviews:

Rate and Review This Site

No reviews yet


Statistic Information About this Resource:


Total Hits: 2011
Unique Hits: 1729


  Daily Weekly Monthly
  Unique Total Unique Total Unique Total
Average 1.3 1.4 7.1 7.7 52.4 59.5
Current 2 2 6 7 30 33
Previous 2 3 10 11 41 44
Jul 22 1 1 7 8 0 0
Jul 21 1 1 8 8 73 87
Jul 20 1 1 9 10 113 128
Jul 19 1 1 0 0 93 101
Jul 18 0 0 12 13 0 0
Jul 17 3 3 7 7 106 122
Jul 16 0 0 12 13 50 57
Jul 15 2 2 0 0 18 23
Highest 23 27 111 138 462 564


Script Execution Time: 7.58882 | SQL Queries: 10 | Members: 501
Ajax Tutorial Top List - Powered by Aardvark Topsites PHP 5.1.2