0

Possible Duplicate:
Forcing to download a file using PHP
PHP - send file to user

Is it possible to serve a file from another server , and change the name. I have all files uploaded in another server but names are changed.I want to hit this server and fetch file from it but want to change it s name. I wrote a simple curl script , but this adds extra traffic to my php server as well so i will be billed twice for each file and more over it will use php memory as well(if file size increases site may crash)

$init   = curl_init();
curl_setopt_array($init, $opArray);
$myFile = curl_exec($init);
$info   = curl_getinfo($init); 
curl_close($init);
headers ....
echo File

All i am interested is in headers part but for this i need to get file into php server can this be avoided ?

Community
  • 1
  • 1
user88975
  • 1,618
  • 3
  • 19
  • 29
  • 1
    the process is the same as for any local file. the only difference is that instead of a local file you use a URL instead of a path name. Whether you use cURL or just any of the stream enabled functions is up to you. – Gordon Nov 13 '11 at 11:12
  • *(reference)* http://php.net/header – Gordon Nov 13 '11 at 11:26

1 Answers1

0

You can use the following headers:

Content-Type: xxx/xxx
Content-Disposition: attachment; filename=theFilenameYouWant.xxx

If you want to avoid heavy memory consumption and if you are using Apache as web server, you can take a look at the mod_xsendfile:

http://codeutopia.net/blog/2009/03/06/sending-files-better-apache-mod_xsendfile-and-php/

Herzult
  • 3,429
  • 22
  • 15