1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with script to move images to different server/host

Discussion in 'PHP' started by kyle422, Aug 25, 2008.

  1. #1
    Hey guys/gals,
    I know very little about PHP so please forgive me ahead of time if this seems easy or I don't describe my question concisely.
    I have two sites and I'm trying to pull some images (actually a lot of images) from one site to the other. I have a database that references a "listing" to each image. The script I have will pull the images but it eventually stops prior to importing all the images. If I run the script again it starts from the beginning of the image folder. I need the script I currently have to do two things: 1st to make the script check to see if the "listing" already has an image associated with it and 2nd if there is already a picture associated with the "listing" check to see if the listing in the folder is newer than the existing one and if so overwrite the image.
    The script "get-images.php" is below. Thanks ahead of time for any help.
    <?php
    
    ini_set("display_errors",true);
    set_time_limit(0);
    error_reporting(E_ERROR);
    $time_start = microtime(true);
    
    include "functions.php";
    
    
    $directory = 'URL FOR NEW IMAGES TO BE PLACED';
    $img_dir = $directory . 'images';
    
    
    
    $conn = getConnected();
    
    $query = "SELECT mlsNo FROM b_fla_data";
    
    $numfound = 0;
    
    // GET ALL THE CURRENT MLS NUMBERS
    $result = mysql_query($query);
    $i = "a";
    
    while ($rows = mysql_fetch_assoc($result)){
    		$i = "a";
    	    echo "URL WITH FOLDER OF IMAGES".$rows['mlsNo'].$i.".jpg\n";
    	    while (@fclose(@fopen("URL WITH FOLDER OF IMAGES".$rows['mlsNo'].$i.".jpg","r"))){
            passthru("wget -nc -P ".$img_dir."URL WITH FOLDER OF IMAGES".$rows['mlsNo'].$i.".jpg");
    	    $numfound++;  
    	    $i++;
    	    }
    }
    
    
    
    echo $numfound . " Sets of Listings Images downloaded.\n";  
    
    
    
    
    ?>
    PHP:

     
    kyle422, Aug 25, 2008 IP
  2. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Will it not be easier to backup the folder on the server as a commpressed image then download and split for uploading to new server and using a php to extract all in the folder?
     
    cornetofreak, Aug 25, 2008 IP
  3. kyle422

    kyle422 Peon

    Messages:
    290
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The folder is rather large (couple of gigs worth of images) and always times out using ftp programs.
    The main reason for wanting the PHP file to work the way I want it to is the folder gets updated each day via a data feed/ftp with new images. I would have a cron job run the PHP each day to update it on the second site/server.
     
    kyle422, Aug 26, 2008 IP