SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem downloading/saving files with php

    hey guys

    I am having troubles finding out if PHP is able to download files and save'em when i
    don't know the name of the file.

    For example:
    I have this page: http://www.site.be/file1/

    If you go to that page you'll see a popup asking to 'save' or 'open' the file called
    'whatever.srt'. I click 'save as..' and download the file to my local drive.

    Simulating this action in PHP seems a problem, I tried it with Curl but don't know
    how to accept the popup when it arrives.

    Does anybody here has a solution to this or an idea where i can find the
    solution? That is if it is possible offcourse.

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Simulating this action in PHP seems a problem, I tried it with Curl but don't know
    how to accept the popup when it arrives.
    Are you trying to 'force' downloads to a visitor's PC?

    If so, you can't do that. Security.

    Or are you trying to save that file on your server? In which case, there is no 'pop-up'.

    Please explain exactly what you're trying to do, and provide some code if you can.

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    download

    When you click on links to certain file types, browsers will present the "download" dialog (technically not a pop-up). As Immerse said, this is a security feature. Using Curl with PHP you should be able to save the file as it is (again, there will be no "pop-up"). If you are having problems, it is most likely because you are not specifying the correct file type.

  4. #4
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying to save this file on my server (or local if you wish as i am running th escript from localhost).

    I want to download a .srt file from for example 'http://www.websites.com/file26/' , can you show me how i would have to do this with curl and how i should specify this filetype.

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    Curl

    I just noticed, Welcome to the forums!
    I not an expert here, but if the file is a binary file, try using curl_setopt(). eg.
    CURLOPT_BINARYTRANSFER
    TRUE to return the raw output when CURLOPT_RETURNTRANSFER is used.

  6. #6
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    ok tnx i'll try it this evening!


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
  •