egaertner Posted April 11, 2008 Share Posted April 11, 2008 I'm trying to write a function that is passed an external url as a parameter (ex: www.remoteServer.com/image.jpg) and stores that file locally on my server, say in my working directory. I've researched the topic for a solution, but I haven't found any that I believe will work with my server, which I am unable to change the parameters on. http://www.nutv.neu.edu/info.php The two problematic sections that jump out at me are that curl_init is under disabled functions, and allow_url_fopen is turned off. Additionally, I can only connect to the server via SFTP, not FTP. Any solutions for this simple task that I'm overlooking, given what I have to work with? Quote Link to comment Share on other sites More sharing options...
egaertner Posted April 11, 2008 Author Share Posted April 11, 2008 fsockopen disabled as well... Quote Link to comment Share on other sites More sharing options...
egaertner Posted April 12, 2008 Author Share Posted April 12, 2008 Bump, any ideas? Or a "hopeless" if that's the case, so I stop going down dead ends. Quote Link to comment Share on other sites More sharing options...
ucffool Posted April 13, 2008 Share Posted April 13, 2008 <?php $url = 'http://some.domain.com/filename.jpg'; $file = file_get_contents($url); file_put_contents('filename.jpg',$file); ?> Quote Link to comment Share on other sites More sharing options...
egaertner Posted April 13, 2008 Author Share Posted April 13, 2008 That gives me a zero byte file unfortunately. Is it perhaps due to permissions? They're set at 0775 so others have no write access, if I change this up to 0777 the pages refuse to load, so I presume thats a security measure of the server host. I also tried to echo $file and got no data output at all, so perhaps its failing at file_get_contents. Quote Link to comment Share on other sites More sharing options...
ucffool Posted April 13, 2008 Share Posted April 13, 2008 <?php $url = 'http://some.domain.com/filename.jpg'; $file = file_get_contents(urlencode($url)); file_put_contents('filename.jpg',$file); ?> Try that. If that fails, probably because of this: php.ini setting allow_url_fopen Quote Link to comment Share on other sites More sharing options...
dsaba Posted April 13, 2008 Share Posted April 13, 2008 You could simply make the file available or available upon secure entry on your current restricted server, like pass a password through the URI through HTTP GET, and then it will give access to your files you wish to transfer THEN, on your remote server (if you can run scripts that is..) you can simply download the files you made available. You can even call such a downloading script FROM your restricted server, making you never have to touch your remote server, and have your restricted server do all the work, giving u the same effect as you originally wanted. (how everything is controlled by restricted server) So instead of uploading files from restricted server to remote server, you can download file from restricted server to remote server. Quote Link to comment Share on other sites More sharing options...
egaertner Posted April 13, 2008 Author Share Posted April 13, 2008 ucffool: Yes, allow_url_fopen is disabled, which is what's making this difficult dsaba: I don't follow exactly. The remote server I'm trying to pull data from is essentially a black box, I don't have any control over it. I'm currently hot linking images from it, which I would like to stop doing for obvious reasons, so I'm trying to automate the process of taking the image and storing it on the local server, so I can simply link the image there. Between the various disabled functions my restricted server seems to have imposed, I can't determine any functions to do what I need. Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted April 14, 2008 Share Posted April 14, 2008 Look up the snoopy library. It uses cURL to allow you to retrieve a remote file using a url. You can do this with a picture using something like this: include ('./snoopy.php'); $url = "http://some.domain.com/filename.jpg"; $snoopy = new Snoopy; if(snoopy->fetch($url)) { $img = snoopy->results; imagepng($img, './filename.jpg'); } else { echo "There was an error, the file was not retrieved."; } I didn't test this and it was all from memory, but snoopy isn't too difficult and it works. Quote Link to comment Share on other sites More sharing options...
egaertner Posted April 14, 2008 Author Share Posted April 14, 2008 Look up the snoopy library. It uses cURL to allow you to retrieve a remote file using a url. You can do this with a picture using something like this: include ('./snoopy.php'); $url = "http://some.domain.com/filename.jpg"; $snoopy = new Snoopy; if(snoopy->fetch($url)) { $img = snoopy->results; imagepng($img, './filename.jpg'); } else { echo "There was an error, the file was not retrieved."; } Unfortunately, looking through that source, it is dependent on fsockopen() to create the initial connection to do anything else. Since that function is disabled on my server, it won't work. I didn't test this and it was all from memory, but snoopy isn't too difficult and it works. Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 14, 2008 Share Posted April 14, 2008 Read the initial post. CURL and url_fopen are both disabled. From what I know, they have built php to not communicate with outside servers... so... I don't think it's possible. Maybe a local server that grabs and uploads for you (via ftp perhaps) and executes a remote script to update anything else needed on the server. Quote Link to comment Share on other sites More sharing options...
egaertner Posted April 15, 2008 Author Share Posted April 15, 2008 Read the initial post. CURL and url_fopen are both disabled. From what I know, they have built php to not communicate with outside servers... so... I don't think it's possible. Maybe a local server that grabs and uploads for you (via ftp perhaps) and executes a remote script to update anything else needed on the server. Hacky, but not a bad idea, and something that certainly could work. Unless I sweet-talk to the IT gods into enabling one of those functions. Thanks Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 15, 2008 Share Posted April 15, 2008 When the best solutions are out of reach, find the one that just works 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.