I wrote my own download script for my site a long time ago (1 year ago) but i'm using just the header php function. That is the only one I actually understand.

header -- Send a raw HTTP header

I've seen some people use the readfile and fopen function (especially to force a download dialog box)...I read up on them on php.net and I don't quite understand how they open files across domains. Says something about a url wrapper and I'm unclear on what that is. Does anyone know what the wrappers do exactly, it seems both fopen and readfile use them. Does this read them through the server and then send them to the client via a stream...if that is the case, that means its only worth using for files hosted on the same server. Or do I have this all wrong...Can anyone shine some light on the difference between fopen, fread, and header are.

Thanks for any help,

Dave

    the difference with fopen and readfile when using url wrappers is that readfile will read the contents of the remote file and output them to the user, where fopen gives you the ability to navigate thru the file stream to different positions or only read certain portions of it.
    what url wrappers really are is the ability to open remote files. normally in c/c++ when you would use fopen, is it would just open the local file, but php extends it to recognize remote files so it will open an http/ftp connection the the file specified. header is quite unrelated to the two functions. where header just sends a header to the users browser.
    if you send the Location header, it will instruct them to go to the page specified, but there are other options that will just tell the browser how to handle the page.
    hope that helped out a little. if you have more questions ill try to answer them.

      great, I assumed correctly then right?

      Thank you so much for the clarification. Then, I'll continue to use the header function for my download script since I'm redirecting to large videos hosting on a remote server. It would be extremely wasteful to use the readfile...

      Ok, one more question. On my download script where i'm using the header redirection. ie. download.php?id=58.

      When I rightclick and save as..it saves as download.php.fileextensionoffile. So, the filename is not what I would like it to be. NOTE: I'm using firefox (mozilla) browser and I tried it on IE and it actually saves correctly...strange. Is there any way I can get this to save as the actual filename itself. Of course I got this working using the readfile since I can send additional headers like content disposition and stuff like that, but i'm trying to do it using a header redirection.

      If you're using firefox or a mozilla browser... Here is an example. (right click and save as). Its a wmv video file. Should be saving as familyguymontage-davescrib.com.wmv its saving as download.php.wmv

      http://davescrib.com/downloads/download.php?id=15&title=FamilyGuyMontage1

        if the person right clicks, im not sure of a way to get it to be the filename it really is. i would assume what internet explorer does when a person right click->save as it actually goes to the file to see what kind of file it is and get its name but mozilla et al do that after you choose to save, and it just names the file whatever the file portion of the url is, (in this case download.php?.....)

          ok..well if u ever find out u know where this thread is...hehe

          Thanks for your time drew.

            Write a Reply...