FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


fetching file form somewhere else and push to user





badai
let say i have a file somewhere and can be download as usual using this url: http://myserver1.com/path/myfile.txt

i have another server, myserver2.com

let say i want to hide the url of my file. so i gave somebody this url: http://myserver2.com/some_unique_path

when he go to that url, his browser will automatically download myfile.txt. but he see the download url is actually http://myserver2.com/some_unique_path instead of http://myserver1.com/path/myfile.txt

also, the download can support resume (multi part is not necessary, but that will be a bonus)

is that possible? myserver2.com have the latest php and mysql and i can install anything on it. i have no access to myserver1.com (except whatever publicly available on http there)

any idea guys?

thanks.
sonam
Hmmm, actually I don't know how to download file from another server. I didn't try because I always insert important files direct in root folder instead of my public_html folder. In that case it is not at possible to see, download or read file without before predefined PATH. I think this is quite secure for .txt, .pdf, .doc files from exploitation. Here is simple code what I am using. Of course I have few checking before, for example are file exist, etc.

Code:
<?php
define("PATH", "/home/your_root/some_folder/");
$file = 'some_file.txt';
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
?>


Sonam
badai
the file will be located somewhere else, not in myserver2.com (as in my first post)

i know i can get the file and save it somewhere and then do as your script to let user download it, but then they have to wait until myserver2.com finish downloading from myserver1.com. if possible i just want it to "redirect" or myserver2.com can like "push" immediately while downloading from myserver1.com.

bottom line here, i want to hide the real url of myfile.txt so that people cannot go there to download.

sonam wrote:
Hmmm, actually I don't know how to download file from another server. I didn't try because I always insert important files direct in root folder instead of my public_html folder. In that case it is not at possible to see, download or read file without before predefined PATH. I think this is quite secure for .txt, .pdf, .doc files from exploitation. Here is simple code what I am using. Of course I have few checking before, for example are file exist, etc.

Code:
<?php
define("PATH", "/home/your_root/some_folder/");
$file = 'some_file.txt';
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
?>


Sonam
sonam
Quote:
i want to hide the real url of myfile.txt so that people cannot go there to download


If you insert file out of public_html folder then it is not at possible to download file directly with typing url in the browser. Visitors can access only files in your public_html folder (and folders in it). In that case you just need one php what can access file out of public_html folder and download it and then, if you want, redirect to another web site.

Sonam
badai
i know that. i think you misunderstood what i want to achieve. basically, both url are publicly accessible (in public_html). one is a real file, one is a php script that somehow mask the the url of the former.

nobody said anything about downloading/accessing anything outside of public_html realm.

anybody else got any idea? like using curl or whatever?

sonam wrote:
Quote:
i want to hide the real url of myfile.txt so that people cannot go there to download


If you insert file out of public_html folder then it is not at possible to download file directly with typing url in the browser. Visitors can access only files in your public_html folder (and folders in it). In that case you just need one php what can access file out of public_html folder and download it and then, if you want, redirect to another web site.

Sonam
sonam
Quote:
i think you misunderstood what i want to achieve.


For sure. Confused

Sonam
Fire Boar
Just using the location header should do the trick.

Code:
header('Location: http://myserver1.com/path/myfile.txt');
badai
doesn't not work as intended. it will show the real path when you download it. i want to totally mask the real url. you can even see in browser's status bar it connect to another server.

Fire Boar wrote:
Just using the location header should do the trick.

Code:
header('Location: http://myserver1.com/path/myfile.txt');
Fire Boar
Well, it's a matter of logistics. You have two options.

1) Transfer the file directly. This requires you to tell the user's browser where the file actually exists, and is the method employed by my suggestion above.

2) Transfer the file via your server. This way, the browser doesn't know where the file was originally from, because it is downloading the file from you. This, naturally, means that you must expend your own bandwidth in the transfer of the file: once for upload, once for download.

I would recommend the first option for bandwidth reasons. If you wish to provide a user-friendly address, consider using a subdomain, like media.example.com, which points to the server on which the file is hosted. Option 2 is a kludge, is not scalable and is never used on real websites unless there is some kind of processing that must be done after retrieving the file before sending it on.
badai
i will go for option 2, don't care about the bandwidth cost. but how?

i already know the real location of the file.
i created the dummy directory in myserver2.com
so what should index.php in myserver2.com/dummy_path do when user click on it?

i prefer not to download it upfront, and only begin when user click on it. i also don't want user to wait until it finished downloading to my server before user start receiving it. this might take some time if the file is big, like 1GB file, it may take 5 minutes.

Fire Boar wrote:
Well, it's a matter of logistics. You have two options.

1) Transfer the file directly. This requires you to tell the user's browser where the file actually exists, and is the method employed by my suggestion above.

2) Transfer the file via your server. This way, the browser doesn't know where the file was originally from, because it is downloading the file from you. This, naturally, means that you must expend your own bandwidth in the transfer of the file: once for upload, once for download.

I would recommend the first option for bandwidth reasons. If you wish to provide a user-friendly address, consider using a subdomain, like media.example.com, which points to the server on which the file is hosted. Option 2 is a kludge, is not scalable and is never used on real websites unless there is some kind of processing that must be done after retrieving the file before sending it on.
Fire Boar
badai wrote:
i prefer not to download it upfront, and only begin when user click on it. i also don't want user to wait until it finished downloading to my server before user start receiving it.


Then you want cURL. However, it is not clear whether it begins to send to the user while data is pending or not - knowing PHP, I'm guessing not but you'll probably want to experiment. Check the documentation on cURL at php.net and do some profiling.
badai
already tried it using CURLOPT_URL. for small files less than 1M it will work. big file will get 500 error.

also, i assume it will download the whole file first before user get the download prompt because there is some waiting time.

any other idea?

Fire Boar wrote:
badai wrote:
i prefer not to download it upfront, and only begin when user click on it. i also don't want user to wait until it finished downloading to my server before user start receiving it.


Then you want cURL. However, it is not clear whether it begins to send to the user while data is pending or not - knowing PHP, I'm guessing not but you'll probably want to experiment. Check the documentation on cURL at php.net and do some profiling.
Fire Boar
Yes, write your own PHP module. What you're trying to do is incredibly unorthodox and I doubt there's anything available which will do it.
Related topics
HTTP AUTH with PHP and mySQL
Creating a new Operating System
Anyone got a site???
How do i make "_derived/nortbots.htm"??
Avoid click here hyperlink in designing a site
Need help with Members area/link adder
All About WoW
How do I install meta tags on my forum
Need help with submitting form
Login System Tutorial Part 1 Creating Registration
FriHost Forum crashes...
What happened to the server 2?
News script
What's the difference between matter and antimatter?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.