Jump to content

fopen, fsockopen... HELP


amarques

Recommended Posts

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.

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.