#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    24
    Rep 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).]
  2. #2
  3. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    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)
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    24
    Rep 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"; }
  6. #4
  7. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    Try fopen.
    Do you really wanted to save the banner locally (waste of disk space) or preferably fetching the banner on demand (per request)?
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    24
    Rep 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
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    24
    Rep 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;
    }
    ?>

Similar Threads

  1. Can't move or delete it!
    By Hykinsel007 in forum Windows Help
    Replies: 3
    Last Post: June 15th, 2004, 04:41 PM
  2. copying files from cd to hard drive
    By MarkP in forum Beginner Programming
    Replies: 3
    Last Post: February 5th, 2004, 04:34 AM
  3. copying files to computer over WAN
    By smtp in forum C Programming
    Replies: 0
    Last Post: January 30th, 2004, 10:36 AM
  4. Copying layers between files
    By Ron Velten in forum Flash Help
    Replies: 9
    Last Post: December 26th, 2003, 06:30 PM
  5. the window did not close while the files are copying
    By linh in forum Visual Basic Programming
    Replies: 2
    Last Post: November 27th, 2003, 10:20 AM

IMN logo majestic logo threadwatch logo seochat tools logo