SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: cURL and AJAX

  1. #1
    SitePoint Member
    Join Date
    May 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cURL and AJAX

    I want to code a PHP application where it will download a file for me when I give it a url. Now, the problem is this. What if the file is 200MB? Say I give the url by a POST form. When I click submit, the server would take a long time getting that 200MB, and I would be stuck waiting for it to download.

    Is there an AJAX way to do it?

    I could call XmlHttpRequest, and call a PHP page where it'll do it in the background (I suppose). Is there a way to update the progress of the download?

    I am not very acquinted with AJAX yet, so any help will be welcomed .

    Thanks a lot!
    A somebody who's into web designing

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,751
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not just make it a standard download (Via content-disposition headers) which is handled seperately from the web page and lets the page continue with what it's doing durning the download process.

  3. #3
    SitePoint Enthusiast thebasti's Avatar
    Join Date
    Aug 2004
    Location
    Novi Sad, Serbia
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could always use ignore_user_abort to make script run even after browser has moved on and set_time_limit to make sure it has enough time to download it.

    Then you could make another page on which the file that is being downloaded will show up when it's finished.

    It's much simpler then messing around with AJAX, although you could probably make something similar.
    "Strategy without tactics is the slowest route to victory.
    Tactics without strategy is the noise before defeat."
    - Sun Tzu
    Icebergist - a web dev blog | Orange Iceberg Web App Development

  4. #4
    SitePoint Member
    Join Date
    May 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think there's a misunderstanding - I want an application to download a file for me on the server, rather than me downloading a file from my application - and hence that's why I wanted AJAX, possibly some kind of feedback as to how much of the file has been downloaded etc...
    A somebody who's into web designing

  5. #5
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you don't want to get stuck waiting, you can do the following: Send the URL via the form to the next page, but then display an image which is actually a php page and have that php page download the file, for example something like <img src="download.php4?file=http://www.bla.com/bla.rar" />. You'd also have to set ignore_user_abort and set_time_limit like thebasti said to make sure the script doesn't time out.
    For the progress bar there's probably a JavaScript version of that. Maybe a search in the JavaScript forum here would help? Search for something like "download progress" or so.


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
  •