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!
It gave an error message "Unable to open remote file. ".
I tried it with Firefox 3.0.14.
I have Apache2.2 server in my local machine.
I saved the file as "saveas.php" and tried the code as http://localhost/saveas.php
With your problem of opening the remote file: Are you sure the URL is correct? Go to that url in your browser and see if it really displays like that once the page is loaded. If the problem still exists once you get the real URL, check your php.ini and make sure allow_url_fopen is set to 1. You can check it in your code by echo ini_get('allow_url_fopen');
FYI - an easier way to get the URL contents is use file_get_contents
$content = file_get_contents('http://www.google.com/');
if ($content !== false) {
// do something with the content
} else {
// an error happened
}
Your next problem is you have not written any code to actually save the file. You'll need to make either a javascript popup for Save As, or echo some HTML form where you can enter the name you want to save it as locally.
Some web sites prevent external scripts from parsing their contents by denying requests without a user-agent string.
You can open a socket connection and send the headers using a more complex method like fsockopen or cURL. There is a browser emulation class that has some features that work like fopen with URL, but I've not tried them http://www.bitfolge.de/index.php?s=befopen
These are more involved techniques and require some knowledge about HTTP headers and debugging skills.