PHP File copy Server1 ==>Server 2
Moderator: General Moderators
PHP File copy Server1 ==>Server 2
Hey. First off, I am new to this community, and I hope that I can become an active member.
Second, I have an issue. I need to know how to take an image from one site (For testing purposes, lets say http://www.google.com/intl/en/images/logo.gif ) and copy it to another server (note that the images will most likely be in PNG format, if that makes a difference).
Now, the server that I get the file from, I have no write access to (or ftp). It would be like viewing a standard webpage. The second server, however, I have full access to. The php script runs on the second server.
Is this possible?
I hope I was clear in my explanation.
Thanks,
scts102
Second, I have an issue. I need to know how to take an image from one site (For testing purposes, lets say http://www.google.com/intl/en/images/logo.gif ) and copy it to another server (note that the images will most likely be in PNG format, if that makes a difference).
Now, the server that I get the file from, I have no write access to (or ftp). It would be like viewing a standard webpage. The second server, however, I have full access to. The php script runs on the second server.
Is this possible?
I hope I was clear in my explanation.
Thanks,
scts102
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
it's quite easy 
PHP 5:
PHP 4:this assumes your server has url wrappers turned on. It's not a whole lot harder to do if they aren't.. just a bit more involved 
[edit] oops messed an argument to fopen()
PHP 5:
Code: Select all
file_put_contents(basename($url),file_get_contents($url));Code: Select all
$fp = fopen(basename($url),'wb');
if($fp) fwrite($fp,file_get_contents($url));
fclose($fp);[edit] oops messed an argument to fopen()
Thank you for the prompt reply.
Sorry to burden you, but I am not very familiar with php....I know echo(), how to use variables, create forms, and access MYSQL, but other than that, I am lost.
Now, I am running php4, so I am using the latter code:
$fp = fopen(basename($url),'wb');
if($fp) fwrite($fp,file_get_contents($url));
fclose($fp);
So, how do I work this code?
Lets say that I have the image link on server 1 stored in $pbb, and I want to copy it to server 2 (where the script is being run) to http://www.example.com/filename.png?
Thanks again!
Sorry to burden you, but I am not very familiar with php....I know echo(), how to use variables, create forms, and access MYSQL, but other than that, I am lost.
Now, I am running php4, so I am using the latter code:
$fp = fopen(basename($url),'wb');
if($fp) fwrite($fp,file_get_contents($url));
fclose($fp);
So, how do I work this code?
Lets say that I have the image link on server 1 stored in $pbb, and I want to copy it to server 2 (where the script is being run) to http://www.example.com/filename.png?
Thanks again!
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
it goes like this:that should write 'logo.gif' (sans quotes) to the script's location on your server.
basename() pulls the filename out of the URL given to it, in this case: logo.gif
fopen() opens a file stream to a specified file.
file_get_contents() is used to acquire the contents of a file into a single string.
fwrite() writes to a stream, in this case $fp;
fclose() closes a stream ($fp);
Code: Select all
$url = 'http://www.google.com/intl/en/images/logo.gif';
$fp = fopen(basename($url),'wb');
if($fp) fwrite($fp,file_get_contents($url));
fclose($fp);basename() pulls the filename out of the URL given to it, in this case: logo.gif
fopen() opens a file stream to a specified file.
file_get_contents() is used to acquire the contents of a file into a single string.
fwrite() writes to a stream, in this case $fp;
fclose() closes a stream ($fp);
Thanks for the explanation, that helped me understand it
You have good patience
I updated the script, and got the following error:
Warning: fopen(http://69.25.18.226/69.25.18.226/pb000001.png): failed to open stream: HTTP wrapper does not support writeable connections. in /home/kaotclan/public_html/pbss/finish.php on line 5
Warning: fclose(): supplied argument is not a valid stream resource in /home/kaotclan/public_html/pbss/finish.php on line 7
The ip you see above is the google example that I provided. It is a correct, working link. Now I assume that the fclose() error is tied to the fopen() error (based on experience in other languages)?
I updated the script, and got the following error:
Warning: fopen(http://69.25.18.226/69.25.18.226/pb000001.png): failed to open stream: HTTP wrapper does not support writeable connections. in /home/kaotclan/public_html/pbss/finish.php on line 5
Warning: fclose(): supplied argument is not a valid stream resource in /home/kaotclan/public_html/pbss/finish.php on line 7
The ip you see above is the google example that I provided. It is a correct, working link. Now I assume that the fclose() error is tied to the fopen() error (based on experience in other languages)?
Yea, I did....dont remember doing that. My mind is going
Anyway, I get a new error:
Warning: fopen(pb000001.png): failed to open stream: Permission denied in /home/kaotclan/public_html/pbss/finish.php on line 6
Warning: fclose(): supplied argument is not a valid stream resource in /home/kaotclan/public_html/pbss/finish.php on line 8
I take it that Server 1 is not allowing this?
Anyway, I get a new error:
Warning: fopen(pb000001.png): failed to open stream: Permission denied in /home/kaotclan/public_html/pbss/finish.php on line 6
Warning: fclose(): supplied argument is not a valid stream resource in /home/kaotclan/public_html/pbss/finish.php on line 8
I take it that Server 1 is not allowing this?