The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Copying Files from onserver to another
Discuss Copying Files from onserver to another in the PHP Development forum on Dev Shed. Copying Files from onserver to another PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 19th, 2000, 03:57 AM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 24
Time spent in forums: 20 m 51 sec
Reputation Power: 0
|
|
I am trying to set up a link excahnge program using php and I need to know how to copy a file from one server to another. See when people change the banner they have displayed they can enter the location of their banner, such as http://them.com/banner.gif and then i need to copy it over to my server and into there dir, such as www.me.com/them/banner.gif.
Does anyone know how i can do this. I have tried many things but nothing has workd so far
[This message has been edited by Aoeex (edited June 19, 2000).]
|

June 19th, 2000, 09:05 AM
|
 |
Full Access
|
|
Join Date: Jun 2000
Location: London, UK
Posts: 2,019
Time spent in forums: 3 sec
Reputation Power: 15
|
|
|
Try something like this: Have a form that posts to the PHP program...
<form method=POST action="copy.php3" enctype=multipart/form-data>
URL of your current banner:
<input type=text name=banner><br>
And the name of your folder:
<input type=text name=folder><br>
<input type=submit name=submit>
</form>
</body></html>
The PHP program would then look like this:
<?
print "Please be patient, this may take a few seconds...";
copy($banner,"full/path/to/$folder/banner.gif");
print "Done!";
?>
This should work. It'll only work if they know what their directory is ("them"). Their directory would also have to exist on the server already: I don't know how do create directories in PHP. Each banner must also be called banner.gif
--------------------------
Alex Greg
(http://www.alex-greg.co.uk)
|

June 19th, 2000, 03:18 PM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 24
Time spent in forums: 20 m 51 sec
Reputation Power: 0
|
|
|
Thanks for the idea but when I tried it I got the same error i did when I tried using the copy () function. This is the error it returns
Warning: Unable to open 'http://www.geocities.com/aoeex/aoeex.jpg' for reading: No such process in
c:home2k-okeithmpublic_html/linkx/copyfromnet.php3 on line 24
I think that PHP's copy() can't accept http:// urls, only file system. So I am guesing that I will have to make my own class/function to copy the file.
Oh and just if you would like to know you can use the mkdir function to make a directory
ex. if(mkdir("/newdir",0777)){ echo "Dir made, Permission set to 777"; }
|

June 19th, 2000, 10:36 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
Try fopen.
Do you really wanted to save the banner locally (waste of disk space) or preferably fetching the banner on demand (per request)?
|

June 19th, 2000, 10:50 PM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 24
Time spent in forums: 20 m 51 sec
Reputation Power: 0
|
|
|
I do actully need to pull the pic of there server and onto mine for now. I know it is a wast of space but I might try a few thins later on which will help with that.
I don't know about the fopen thoug. havn't really tried anything like that before. I had tried using the file() function to save it into an array but that didn't work. Do ya think mayb if i open both file at the same time and write to one and i read the other it will work?
Something like
$fd=fopen($them,"r");
$fd2=fopen($me,"w");
might work. I'll have to try it later on
|

June 20th, 2000, 12:27 AM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 24
Time spent in forums: 20 m 51 sec
Reputation Power: 0
|
|
|
Well i finally got it. If anyone wants it the code that i came up with is
<?
if ($banner){
print "Please be patient, this may take a few seconds...<BR><BR><BR>";
$them=$banner;
$me="/path/to/file/$localname";
$fi=fopen($them,"r");
$fl=fopen($me,"w");
while(!feof($fi)){
fwrite($fl,fread($fi,15360));
}
fclose($fl);
fclose($fi);
chmod($me,0644);
print "<BR><BR><BR>Done!<BR>
exit;
}
?>
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|