I have the following photos:
product-1.jpg
product-2.jpg
product-3.jpg
product-4.jpg
I have the following request (came from jQuery's sortable
):
action=save&photos=photo[]=4&photo[]=2&photo[]=3&photo[]=1
I've tried this:
<?php
if($_POST) {
if($_POST['action'] == 'save') {
parse_str($_POST['photos'], $photos);
$id_new = 1;
foreach($photos['photo'] as $id) {
rename(dirname(__FILE__) . '/product-' . $id . '.jpg', dirname(__FILE__) . '/product-' . $id_new . '.jpg');
$id_new++;
}
}
}
?>
But rename
deletes some of the photos.