/** * Move images from one folder to another * * @param array|int $pic_ids ID's of the images * @param int $dest_gid destination gallery * @return void */ static function move_images($pic_ids, $dest_gid) { $errors = ''; $count = 0; if (!is_array($pic_ids)) { $pic_ids = array($pic_ids); } // Get destination gallery $destination = flagdb::find_gallery($dest_gid); $dest_abspath = WINABSPATH . $destination->path; if ($destination == null) { flagGallery::show_error(__('The destination gallery does not exist', 'flag')); return; } // Check for folder permission if (!is_writeable($dest_abspath)) { $message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?', 'flag'), $dest_abspath); flagGallery::show_error($message); return; } // Get pictures $images = flagdb::find_images_in_list($pic_ids); foreach ($images as $image) { $i = 0; $tmp_prefix = ''; $destination_file_name = $image->filename; // check if the filename already exist, then we add a copy_ prefix while (file_exists($dest_abspath . '/' . $destination_file_name)) { $tmp_prefix = 'copy_' . $i++ . '_'; $destination_file_name = $tmp_prefix . $image->filename; } $destination_path = $dest_abspath . '/' . $destination_file_name; $destination_thumbnail = $dest_abspath . '/thumbs/thumbs_' . $destination_file_name; // Move files if (!@rename($image->imagePath, $destination_path)) { $errors .= sprintf(__('Failed to move image %1$s to %2$s', 'flag'), '<strong>' . $image->filename . '</strong>', $destination_path) . '<br />'; continue; } // Move the thumbnail, if possible @rename($image->thumbPath, $destination_thumbnail); // Change the gallery id in the database , maybe the filename if (flagdb::update_image($image->pid, $dest_gid, $destination_file_name)) { $count++; } } if ($errors != '') { flagGallery::show_error($errors); } $link = '<a href="' . admin_url() . 'admin.php?page=flag-manage-gallery&mode=edit&gid=' . $destination->gid . '" >' . $destination->title . '</a>'; $messages = sprintf(__('Moved %1$s picture(s) to gallery : %2$s .', 'flag'), $count, $link); flagGallery::show_message($messages); return; }