dowlaoding file problem....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
deaa
Forum Newbie
Posts: 3
Joined: Fri Sep 07, 2007 11:25 am

dowlaoding file problem....

Post by deaa »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I use this script when user request mp3 file to download it from local server:
----------------------------------------------------------

Code: Select all

$download="aaaa.mp3";

$mm_type="application/octet-stream";

header("Cache-Control: public, must-revalidate");
header("Pragma: hack");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)filesize($download) );
header('Content-Disposition: attachment; filename="'.basename($download).'"');
header("Content-Transfer-Encoding: binary\n");


$fp = fopen($download, 'rb');
$buffer = fread($fp, filesize($download));
fclose ($fp);
print $buffer;
--------------------------------------------------------------

but my problem is to do the same thing for letting my users downloading my files that exist in another server (mine server too):

I used this but failed:

-----------------------------------------------------------------------

Code: Select all

$connid=ftp_connect("my remote server");
$logresult=ftp_login($connid,"user","psw");


if ((!$connid) || (!$logresult)) {
        echo "FTP connection has failed!";
        exit;
}

else {

$file = "/files/aaa.mp3";
$download_size = ftp_size($connid, $file);
}

header("Cache-Control: public, must-revalidate");
header("Pragma: hack");
header("Content-Type: " . $mm_type);
header("Content-Length: " .$download_size);
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header("Content-Transfer-Encoding: binary\n");


$fp = fopen($file, 'rb');
$buffer = fread($fp, $download_size);
fclose ($fp);
ftp_close($connid);
print $buffer;
------------------------------------------------------

please advise me how to do that


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: dowlaoding file problem....

Post by Christopher »

Unless you have the remote drive mounted (by NFS for example), it should be:

Code: Select all

$file = "http://www.myservertoo.com/files/aaa.mp3";
You will need to set your PHP configuration to enable opening remote files.
(#10850)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

In this case ftpfs seems like something you may want to investigate on...
deaa
Forum Newbie
Posts: 3
Joined: Fri Sep 07, 2007 11:25 am

Re: dowlaoding file problem....

Post by deaa »

arborint wrote:Unless you have the remote drive mounted (by NFS for example), it should be:

Code: Select all

$file = "http://www.myservertoo.com/files/aaa.mp3";
You will need to set your PHP configuration to enable opening remote files.
opening remote files enabled in my configuration......
and I put the full URL but forget to mention that in my post :) but this solution didn't succeed however when I click on the file to download it the system download 3-5 kb instead of 5mb !!



my current solution is:

Code: Select all

header('Location: ' . $fullURL);
but I didn't like this solution because when I do that the page open the file in any existing player like Quicktime in the browser.

I want to display the downloading window (open , save..) to the user without doing save target as...
deaa
Forum Newbie
Posts: 3
Joined: Fri Sep 07, 2007 11:25 am

Post by deaa »

any one can help ?

or give me any code that let me the ability to solve my problem.

I want that my local server (which include the php code ) treat the remote server as "local" one
Post Reply