Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    32
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Load Remote Images then Upload to Server

    So using range and foreach, I displayed a bunch of images from a remote website on a page. The script I used is posted below. Now, I want to somehow upload them directly to my server and then rename them (which I already know how to do). Can someone please tell me if this is entirely possible, if so, how can I [grab remote files and directly upload them to my server]?

    PHP Code:
      $n $_GET['n'];

      foreach (
    range('1','692') as $number) {
         echo 
    '<img src="http://mywebsite.com/' $n '/prefix_' .$number '.png" />';
      } 
    PHP Code:
      foreach (range('1','692') as $number) {
        
    $oldname "prefix_" $number ".png";
        
    $newname $number ".png";
        
    rename($oldname,$newname);
      } 

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Probably the easiest way is to use PHP GD.

    You loop through the remote images and simply create from PNG and save.

    like this:
    PHP Code:
    <?php

    // Destination directory path.
    $path="../photos/";

    // Loop through the remote image URL list that you have ...

    $filename "http://www.mysite.com/whatever.png"
    $im imagecreatefrompng($filename);

    // process it here if you wish.
    // resize, 24bit conversions, opacity, etc.

    //And save it
    $file=$path.$filename;
    imagepng($im,$file);    

    // clear memory
    imagedestroy($im);  
      
    // end of loop

    ?>

  • #3
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    or use file_get_contents() and just write it to a file.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    You could also use copy().
    PHP Code:
    copy'http://www.example.com/images/their_image.png''./my_image.png' ); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •