amarques Posted March 25, 2008 Share Posted March 25, 2008 Hi all, I need a little script that connects to a remote web server, reads the contents of a file and writes them in a local file. Something like www.example1.com -> connects to www.example2.com and reads file -> wites file in www.example1.com. The problem I'm facing is that I need this to work independently of safe_mode and allow_url_fopen being set or not in www.example1.com. I tried using fopen and it worked very well if allow_url_fopen is set. Same thing for copy(). How would you do it? My next approach was using fsockopen but I'm very new to all this and can't make it work. Is there any other way to do it? Would fsockopne even work on a safe_mode set server? Thanks for any help. Quote Link to comment Share on other sites More sharing options...
Caesar Posted March 25, 2008 Share Posted March 25, 2008 Found a random text file on google and tested this simple code... <?php $source = file_get_contents('http://www.ccp14.ac.uk/ccp/ccp14/ftp-mirror/nist-texture/test.txt'); $handle = fopen('logs/log_'.time(), "w"); //Assuming you are saving to a folder 'logs' and that it is set to CHMOD '777' fwrite($handle, $source); fclose($handle); ?> Quote Link to comment Share on other sites More sharing options...
amarques Posted March 25, 2008 Author Share Posted March 25, 2008 Thanks... But would file_get_contents work if allow_url_fopen is set to off? Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 25, 2008 Share Posted March 25, 2008 If it is a remote file, no. Quote Link to comment Share on other sites More sharing options...
amarques Posted March 25, 2008 Author Share Posted March 25, 2008 Yeap, that is my problem. And what about fsockopen? Would it work opening a remote file even if allow_url_fopen is off? Quote Link to comment Share on other sites More sharing options...
Caesar Posted March 25, 2008 Share Posted March 25, 2008 You can use curl. Quote Link to comment Share on other sites More sharing options...
amarques Posted March 25, 2008 Author Share Posted March 25, 2008 curl can only be used if the library is installed. I need a more "universal" method. That is why I'm asking if fsockopen would work even if safe_mode is on and allow_url_fopen is off. Quote Link to comment Share on other sites More sharing options...
Caesar Posted March 25, 2008 Share Posted March 25, 2008 You seem pretty limited. That makes for sucky options. May want to reconsider using your current host. ...Just saying. Quote Link to comment Share on other sites More sharing options...
amarques Posted March 25, 2008 Author Share Posted March 25, 2008 I am limited... but has nothing to do with my host... Simply this script will be installed on 20 or 30 different sites with probably as many different hosts. And somehow it needs to be compatible with every possible setting on those hosts. Any idea on what is the best approach? I'm going to use a conditional, sort of, if allow_url_fopen is 1 the use fopen, if exists curl_init use curl, and if none of the above, use fsock... Just want to make sure that I'm covered... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.