Jump to content

rename images in directory based on query result


ryan king

Recommended Posts

hi, I have recently migrated one mysql database to another. the last thing I need now is images. I have already migrated the image names, ect to the new table from the old. but the old db just had cd/imagename.jpg in the field..

my new database requires that all images be placed in the user id's subdirectory and renamed..

 

basicly, I just need to move all the images from a directory they are now stored in and put them into the correct user_id subdirectory and rename them.. heres what I have so far.. it echo's the correct results but nothing gets copied, I have all directories permissioned correctly

 

$result = mysql_query("SELECT zoo_products.products_id, jamroom_store.band_id, jamroom_store.item_id, jamroom_store.item_image_name FROM jamroom_store LEFT JOIN zoo_products ON zoo_products.products_id = jamroom_store.item_id ORDER BY jamroom_store.item_id ASC"); 
while($row = mysql_fetch_array($result)) 
{

rename("../selecto/CD/{$row['item_image_name']}", "../selecto/members/{$row['band_id']}/item_{$row['item_id']}");

    echo "<table>";
    echo "<tr><td>{$row['item_id']}";
    echo "</td>";
    echo "<td>{$row['item_image_name']}";
    echo "</td>";
    echo "<td>{$row['band_id']}";
    echo "</td>";

    echo "</td></tr>";
  }
echo "</table>";
?>

 

it need to go from selecto/cd/imagename.jpg  to  selecto/members/$BAND_ID/item_$ITEM_ID.jpg

 

 

Link to comment
Share on other sites

Yes, the directories all exists.. I get this error

 

The file ../selecto/CD/090431620229.jpg does not exist

Warning: rename(/selecto/CD/090431620229.jpg,/selecto/members/5359/item_5067.jpg)

 

the file 090431620229.jpg  is available in the  selecto/CD directory and members/5359 directory is also there..

 

Link to comment
Share on other sites

accualy, I take that back..the images are not available.. I had all 5700 of them in there..now it says there are only 307.. so..somewhere along the line..some images got moved..I cant see them in any of the members directories so i dont know where they went..re uploading them now.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.