A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearWhats a better way to write this function. Its gets a remote file and copys it localy, in php - page 1
User InfoPosts
Whats a better way to write this function. Its gets a remote file and copys it localy, in php#1
So yea, im working on a windows system and while this works locally, know it will break on other peoples servers. Whats a cross platform way to do the same as this

function fetch($get,$put){
file_put_contents($put,file_get_contents($get));
}

posted date: 2009-04-11 22:34:00


Re: Whats a better way to write this function. Its gets a remote file and copys it localy, in php#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-11 22:34:01


Re: Whats a better way to write this function. Its gets a remote file and copys it localy, in php#3
Why will it break on other's people servers? as long as the fopen wrappers are enabled the above will work.

posted date: 2009-04-11 22:36:00


Re: Whats a better way to write this function. Its gets a remote file and copys it localy, in php#4
I don(t see why that would fail unless the other computer is on PHP4. What you would need to do to make that backwards compatible is add functionality to provide replacements for file_get_contents & file_put_contents:if(version_compare(phpversion(),(5(,(<()) { function file_get_contents($file) { // mimick functionality here } function file_put_contents($file,$data) { // mimick functionality here }}

posted date: 2009-04-11 22:53:00


Re: Whats a better way to write this function. Its gets a remote file and copys it localy, in php#5
Shawn(s answer is absolute correct, the only thing is that you need to make sure your $put varialable is a valid path on either the Windows Server on the Unix server.

posted date: 2009-04-11 23:00:00


Re: Whats a better way to write this function. Its gets a remote file and copys it localy, in php#6
well when i read your question I understood you wanted to bring a file from a remote server to your server locally, this can be done with the FTP extension from php http://www.php.net/manual/en/function.ftp-fget.phpif this is not what you intent I believe what shawn says is correctelse tell me in the comments and i(ll help you more

posted date: 2009-04-11 23:20:00


Re: Whats a better way to write this function. Its gets a remote file and copys it localy, in php#7
If the fopen wrappers are not enabled, the curl extension could be: http://php.net/curl

posted date: 2009-04-11 23:39:00


Re: Whats a better way to write this function. Its gets a remote file and copys it localy, in php#8
if it is a v4 vs v5 issue, pear.php.net/package/PHP_Compat has file_put_contents() (file_get_contents is in v4.3+)

posted date: 2009-04-12 00:38:00


Re: Whats a better way to write this function. Its gets a remote file and copys it localy, in php#9
Here would be the solution using simple file operations:<?php$file = "http://www.domain.com/thisisthefileiwant.zip";$hostfile = fopen($file, (r();$fh = fopen("thisisthenameofthefileiwantafterdownloading.zip", (w();while (!feof($hostfile)) { $output = fread($hostfile, 8192); fwrite($fh, $output);}fclose($hostfile);fclose($fh);?>Ensure your directory has write permissions enabled. (CHMOD)Therefore, a replacement for your fetch($get, $put) would be:function fetch($get, $put) { $hostfile = fopen($get, (r(); $fh = fopen($put, (w(); while (!feof($hostfile)) { $output = fread($hostfile, 8192); fwrite($fh, $output); } fclose($hostfile); fclose($fh);}Hope it helped! =)Cheers, KrX

posted date: 2009-04-12 04:35:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.